// additional test static void BottomInts() { int[] allInts = { 12, 11, 8, 7, 9, 5, 4, 3, 2, 29, 23, 1, 24, 30, 9, 4, 88, 5, 100, 29, 23, 5, 99, 87, 22, 111 }; MaxPQ <int> pq0 = new MaxPQ <int>(allInts); int M = allInts.Length / 3; MaxPQ <int> pq = new MaxPQ <int>(M + 1); Console.WriteLine("Top {0} is ", M); foreach (var n in allInts) { pq.Insert(n); Console.WriteLine("Max is {0}", pq.Max); // remove maximum if M+1 entries on the PQ if (pq.Count > M) { pq.DelMax(); } } // print entries on PQ in reverse order LinkedStack <int> stack = new LinkedStack <int>(); foreach (int n in pq) { stack.Push(n); } foreach (int n in stack) { Console.WriteLine(n); } Console.WriteLine("These are the bottom elements"); }
public static void MainTest(string[] args) { TextInput StdIn = new TextInput(); MaxPQ <string> pq = new MaxPQ <string>(); while (!StdIn.IsEmpty) { string item = StdIn.ReadString(); if (!item.Equals("-")) { pq.Insert(item); } else if (!pq.IsEmpty) { Console.Write(pq.DelMax() + " "); } } Console.WriteLine("(" + pq.Count + " left on pq)"); }