本文整理汇总了C#中OrderedBag.AddMany方法的典型用法代码示例。如果您正苦于以下问题:C# OrderedBag.AddMany方法的具体用法?C# OrderedBag.AddMany怎么用?C# OrderedBag.AddMany使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OrderedBag
的用法示例。
在下文中一共展示了OrderedBag.AddMany方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main()
{
var bag = new OrderedBag<Product>();
var products = ProductsGenerator.Generate(500000);
bag.AddMany(products);
PrintProductsInRange(20, 1000, bag);
MakeSearches(10000, 1, 5000, bag);
}
示例2: GetMinimalspanningTreeUsingPrim
public static List<Edge<int>> GetMinimalspanningTreeUsingPrim(List<Edge<int>> graph, int start)
{
var result = new List<Edge<int>>();
var priority = new OrderedBag<Edge<int>>();
var visited = new HashSet<int>();
visited.Add(start);
foreach (var edge in graph)
{
if (edge.Start == start || edge.End == start)
{
priority.Add(edge);
}
}
while (priority.Count > 0)
{
var current = priority.RemoveFirst();
if (!(visited.Contains(current.Start) && visited.Contains(current.End)))
{
result.Add(current);
}
if (visited.Contains(current.Start) && !visited.Contains(current.End))
{
priority.AddMany(graph.Where(x => x.Start == current.End || x.End == current.End));
visited.Add(current.End);
}
else if (!visited.Contains(current.Start) && visited.Contains(current.End))
{
priority.AddMany(graph.Where(x => x.Start == current.Start || x.End == current.Start));
visited.Add(current.Start);
}
}
return result;
}
示例3: Main
static void Main(string[] args)
{
var products = new OrderedBag<Product>();
products.AddMany(
new Product[]
{
new Product("Grabage", 24),
new Product("Grabage 2", 22),
new Product("Grabage 3", 290),
new Product("Grabage 4", 29)
});
var result = products.Range(
new Product("", 20), true,
new Product("", 30), true);
foreach (var item in result)
{
Console.WriteLine(item.ProductName);
}
}
示例4: Dijkstra
private static int Dijkstra(Node[] graphMatrix, int hospital)
{
OrderedBag<Connection> streets = new OrderedBag<Connection>();
Node currentNode = graphMatrix[hospital];
currentNode.TempDistance = 0;
currentNode.PermanentDistance = 0;
currentNode.Visited = true;
streets.AddMany(currentNode.ChildsList);
while (streets.Count != 0) // streets.Count == num of streets
{
foreach (Connection child in currentNode.ChildsList)
{
if (graphMatrix[child.Node].TempDistance >
child.Value + currentNode.PermanentDistance)
{
graphMatrix[child.Node].TempDistance =
child.Value + currentNode.PermanentDistance;
}
}
int nextNode = streets.RemoveFirst().Node;
if (graphMatrix[nextNode].Visited == false)
{
currentNode = graphMatrix[nextNode];
streets.AddMany(currentNode.ChildsList);
currentNode.PermanentDistance = currentNode.TempDistance; currentNode.Visited = true;
}
}
int minDistance = 0;
for (int i = 1; i < graphMatrix.Length; i++ )
{
if (!hospitals.Contains(graphMatrix[i].ID))
{
minDistance += graphMatrix[i].PermanentDistance;
}
}
return minDistance;
}