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(); }
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). } }
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); }