static void Main() { int num; //max number of strings in the heap string input; //from keyboard MaxHeap m; //module containing all heap functions //get the max number of strings in the heap input = Console.ReadLine(); Int32.TryParse(input, out num); //create heap of max size "num" m = new MaxHeap(num); Stopwatch sw = Stopwatch.StartNew(); //get all the strings from input for (int i = 0; i < num; i++) { input = Console.ReadLine(); m.Insert(input); } Console.Write(num); m.HeapSort(); //sort the heap sw.Stop(); m.Print_Array(); //print sorted elements Console.WriteLine("\nElapsed time in seconds: " + sw.ElapsedMilliseconds); }
/// <summary> /// Runs the heap test. /// </summary> static void runHeapTest() { int numberOfEntries; Console.WriteLine("Input the number of strings you would like to put in.\n"); numberOfEntries = int.Parse(Console.ReadLine()); heap = new MaxHeap(numberOfEntries); for (int i = 1; i <= numberOfEntries; i++) { heap.Insert(Console.ReadLine()); } heap.Print(); Console.ReadKey(); }
static void Main(string[] args) { string quit = ""; while (quit != "quit") { Console.WriteLine("Enter the size for the heap: "); int max_size = Int32.Parse(Console.ReadLine()); MaxHeap maxHeap = new MaxHeap(max_size); for (int i = 0; i < max_size; i++) { Console.WriteLine("\nEnter a string to be entered into the heap: "); maxHeap.Insert(Console.ReadLine()); } maxHeap.HeapSort(); maxHeap.Print(); Console.WriteLine("Enter 'quit' to exit, or enter to sort another heap: "); quit = Console.ReadLine(); } }