本文整理汇总了C#中PriorityQueue.Enque方法的典型用法代码示例。如果您正苦于以下问题:C# PriorityQueue.Enque方法的具体用法?C# PriorityQueue.Enque怎么用?C# PriorityQueue.Enque使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PriorityQueue
的用法示例。
在下文中一共展示了PriorityQueue.Enque方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main()
{
PriorityQueue<int> pq = new PriorityQueue<int>();
pq.Enque(2);
pq.Enque(3);
pq.Enque(4);
pq.Enque(1);
Console.WriteLine(pq.Peek());
Console.WriteLine(pq.Deque());
Console.WriteLine(pq.Peek());
Console.WriteLine(pq.Count);
}
示例2: Main
static void Main()
{
PriorityQueue<int> myHeap = new PriorityQueue<int>(36);
myHeap.Enque(12);
myHeap.Enque(42);
myHeap.Enque(83);
myHeap.Dequeue();
myHeap.Enque(52);
myHeap.Enque(66);
myHeap.Enque(3);
myHeap.Enque(7);
myHeap.Enque(19);
myHeap.Enque(43);
myHeap.Enque(96);
Console.WriteLine();
foreach (int element in myHeap)
{
Console.WriteLine(element);
}
}
示例3: Dijkstra
// Dijkstra algorithm with priority queue (changes values in static graph)
public static Graph Dijkstra(Graph graph, GraphNode source)
{
PriorityQueue<GraphNode> q = new PriorityQueue<GraphNode>();
source.Distance = 0;
q.Enque(source);
while (q.Count != 0)
{
var current = q.Deque();
foreach (var v in current.Edges)
{
var alt = current.Distance + v.Value;
if (alt < graph.Elements[v.Key].Distance)
{
graph.Elements[v.Key].Distance = alt;
q.Enque(graph.Elements[v.Key]);
}
}
}
return graph;
}
示例4: Main
static void Main()
{
// Testing priority queue
var testQue = new PriorityQueue<int>();
testQue.Enque(1);
testQue.Enque(5);
testQue.Enque(-87);
testQue.Enque(67);
testQue.Enque(98);
testQue.Enque(6765);
testQue.Enque(12);
testQue.Enque(1);
testQue.Enque(-2);
testQue.Enque(-5);
testQue.Enque(1);
testQue.Enque(1);
testQue.Enque(231);
testQue.Enque(11);
int numberOfEntries = testQue.Count;
for (int i = 0; i < numberOfEntries -1; i++)
{
Console.WriteLine(testQue.Dequeue());
}
// Testing products task
OrderedBag<Product> tryBag = new OrderedBag<Product>();
tryBag.Add(new Product("Mlqko", 55.76M));
tryBag.Add(new Product("Hlqb", 56M));
tryBag.Add(new Product("Maslo", .6M));
tryBag.Add(new Product("Kroasan", 5.76M));
tryBag.Add(new Product("Biskviti", 5.76M));
tryBag.Add(new Product("Zele", 355.76M));
tryBag.Add(new Product("Fystyci", 765.76M));
tryBag.Add(new Product("Shokolad", 1.76M));
var fromRangeProduct = new Product("test", 5m);
var currentView = tryBag.RangeFrom(fromRangeProduct, true);
foreach (var product in currentView)
{
Console.WriteLine("{0} has price of -> {1}", product.Name, product.Price);
}
// Test counting words
string testText = "the ther the ther thir them t a m";
string[] words = testText.Split(' ');
Trie checkIt = new Trie();
for (int i = 0; i < words.Count(); i++)
{
checkIt.Insert(words[i]);
}
var result = checkIt.CountWords();
foreach (var pair in result)
{
Console.WriteLine("The word === {0} === can be found === {1} === times in the text", pair.Key, pair.Value);
}
}