本文整理汇总了C#中System.Collections.Generic.PriorityQueue.isEmpty方法的典型用法代码示例。如果您正苦于以下问题:C# PriorityQueue.isEmpty方法的具体用法?C# PriorityQueue.isEmpty怎么用?C# PriorityQueue.isEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Generic.PriorityQueue
的用法示例。
在下文中一共展示了PriorityQueue.isEmpty方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
// Print the top M lines in the input stream.
Console.Write("Write Lenth : ");
int M = int.Parse(Console.ReadLine());
Console.Write("Write Del max(True) or min(False) : ");
bool b = false;
bool.TryParse(Console.ReadLine(),out b);
PriorityQueue<int> pq = new PriorityQueue<int>(M,b);
Console.WriteLine("Insert Queue : ");
for(int i=0;i<M;i++)
pq.Insert(int.Parse(Console.ReadLine()));
Stack<int> stack = new Stack<int>();
while (!pq.isEmpty())
stack.push(pq.Del());
Console.WriteLine("\n\t OutPut Stack");
while(!stack.isEmpty())
Console.WriteLine(stack.pull());
Console.ReadKey();
}
示例2: crossing
private PriorityQueue<Edge> pq; // crossing (and ineligible) edges
#endregion Fields
#region Constructors
public LazyPrimMST(EdgeWeightedGraph G)
{
pq = new PriorityQueue<Edge>(G.V);
marked = new bool[G.V];
mst = new Queue<Edge>();
visit(G, 0); // assumes G is connected (see Exercise 4.3.22)
while (!pq.isEmpty())
{
Edge e = pq.Del(); // Get lowest-weight
int v = e.either;
int w = e.other(v); // edge from pq.
if (marked[v] && marked[w])
continue; // Skip if ineligible.
mst.Enqueue(e); // Add edge to tree.
if (!marked[v])
visit(G, v); // Add vertex to tree
if (!marked[w])
visit(G, w); // (either v or w).
}
}
示例3: Main
static void Main(string[] args)
{
string input;
string result;
List<Node> closed = new List<Node>();
PriorityQueue<Node> open = new PriorityQueue<Node>();
Console.WriteLine("enter initial string set: ");
input = Console.ReadLine();
Console.WriteLine("Enter desired string set: ");
result = Console.ReadLine();
Node start = new Node(input);
Node goal = new Node(result);
start.G = 0; //set G to amount of nodes traversed aka priority
start.SetH(goal); //set the h value based on the goal node's value
Node current = start;
open.Enqueue(current); //add current node into open list
while (open.Peek() != goal)
{
//generate children based on items in open list (current)
List<Node> Children = getChildren(current, closed, open);
current = open.Dequeue(); //pop current node
closed.Add(current); //add current node into closed list
//Console.WriteLine(current.GameString);
foreach (Node child in Children)
{
//child.SetH(goal);
open.Enqueue(child);
}
if (current.Equals(goal))
{
Console.WriteLine("found path:");
Node last = current;
List<Node> list = new List<Node>();
while (last.Parent != null)
{
list.Add(last);
last = last.Parent;
}
list.Add(last);
list.Reverse();
foreach (Node n in list)
Console.WriteLine(n.ToString());
break;
}
if (open.isEmpty())
{
Console.WriteLine("failed to find path");
break;
}
if (Children == null)
{
current = open.Dequeue(); //set first element of open list to current and pop
continue;
}
}
Console.ReadKey(true);
}