/// <summary> /// This is the entry point of the program /// </summary> public static void Main() { //Console.Write("Number of strings: "); int strings = int.Parse(Console.ReadLine()); //Number of things to put into the heap MaxHeap heap = new MaxHeap(strings); //Create object //for (int i = 0; i < strings; i++) //{ // Console.Write($"String #{i + 1}: "); // heap.Insert(Console.ReadLine()); //} //Insert into heap one line at a time for (int i = 0; i < strings; i++) { heap.Insert(Console.ReadLine()); } heap.HeapSort(); //sort the heap //Console.Write("\nSorted: "); heap.PrintArray(); //Console.WriteLine("\n\t\tPress a key to continue..."); Console.ReadLine(); }
public static void Main(String[] args) { int numStrings, Num; string input, numS; //prompt for the number of values being placed into the MaxHeap Console.Write("Number of values in the Heap: "); numS = Console.ReadLine(); numStrings = Convert.ToInt32(numS); MaxHeap heap = new MaxHeap(numStrings); //prompt user to enter strings one at a time //insert each string one at a time into heap Console.WriteLine("\n\nEnter values one at a time: "); do { input = Console.ReadLine(); Num = Convert.ToInt32(input); heap.Insert(Num); numStrings--; }while (numStrings > 0); //Display the MaxHeap before sorting Console.WriteLine("\n\nExtract-Max to sort Heap..\n"); Console.WriteLine("Before sort: "); heap.Print(); Console.WriteLine("\n"); //time how long it takes to sort the MaxHeap //use Print_Array to display after extracting due to loss of size variable Stopwatch sw = Stopwatch.StartNew(); heap.HeapSort(); sw.Stop(); //print the contents of the MaxHeap after sorting using Extract-Max Console.WriteLine("After sort: "); heap.Print_Array(); //display the time it took to sort the maxHeap Console.WriteLine("\nTime it took to sort using Extract-Max: {0}", sw.Elapsed.TotalMilliseconds / 1000); //pause for display Console.ReadLine(); }