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