private static void TestHeap() { MinHeap <int> myHeap = new MinHeap <int>(); int N = 17; for (int i = 0; i < N; i++) { int nextValue = randGen.Next(0, 1000); myHeap.AddValue(nextValue); Console.WriteLine(nextValue); } Console.WriteLine(myHeap); myHeap.RemoveTop(); Console.WriteLine(myHeap); }
public static void Main(string[] args) { int SIZE = 127; Random r = new Random(); for (int i = 0; i < 1; i++) { MinHeap <int> mh = new MinHeap <int>(); for (int x = 0; x < SIZE; x++) { mh.Add(r.Next(1000, 9999)); } Console.WriteLine("Size: {0}\nInsert Compares: {1}\n", SIZE, mh.NumCompares, mh.NumMoves); mh.ClearStats(); int count = 0; while (mh.Count > 0) { int z = mh.RemoveMin(); /* * count++; * Console.Write("{0,5}", z); * count %= 10; * if (count == 0) * Console.WriteLine(); */ } Console.WriteLine(); Console.WriteLine("Size: {0}\nRemove Compares: {1}\n", SIZE, mh.NumCompares, mh.NumMoves); mh.ClearStats(); SIZE *= 2; SIZE++; } Console.ReadLine(); }