static void Main(string[] args) { MinHeap minHeap = new MinHeap(10); minHeap.Insert(7); minHeap.Insert(2); minHeap.Insert(4); minHeap.Insert(1); minHeap.Insert(12); minHeap.Insert(8); Console.WriteLine("Min number now = " + minHeap.GetMin()); Console.WriteLine("Min number now = " + minHeap.ExtractMin()); Console.WriteLine("Min number now = " + minHeap.GetMin()); Console.Read(); }
static void Main(string[] args) { int[] numbers = { 5, 3, 10, 1, 4, 2 }; var heap = new Heap(); foreach (var number in numbers) { heap.Insert(number); } for (int i = numbers.Length - 1; i >= 0; i--) { numbers[i] = heap.Remove(); } //Console.WriteLine(string.Join(", ", numbers)); //Heap heap = new Heap(); //heap.Insert(10); //heap.Insert(5); //heap.Insert(17); //heap.Insert(4); //heap.Insert(22); //Console.WriteLine(heap.Remove()); //int[] numbers2 = { 5, 3, 8, 4, 1, 2 }; ////MaxHeap.Heapify(numbers2); //Console.WriteLine(MaxHeap.GetKthLargest(numbers2,2)); MinHeap minHeap = new MinHeap(); minHeap.Insert(5, "A"); minHeap.Insert(3, "B"); minHeap.Insert(8, "C"); minHeap.Insert(4, "D"); minHeap.Insert(1, "E"); minHeap.Insert(2, "F"); Console.ReadKey(); }
static void Main(string[] args) { var unsorted = new[] { 3, 2, 1, 7, 8, 4, 10, 16, 12 }; var minHeap = new MinHeap(unsorted); var maxHeap = new MaxHeap(unsorted); var l = minHeap.Length(); Console.Write("Array in ascending order : "); for (var i = 0; i < l; i++) { Console.Write(minHeap.ExtractMin() + " "); } Console.WriteLine(); var l1 = maxHeap.Length(); Console.Write("Array in descending order : "); for (var i = 0; i < l1; i++) { Console.Write(maxHeap.ExtractMax() + " "); } Console.WriteLine(); }
static void Main(string[] args) { Heap heap = new Heap(); heap.insert(10); heap.insert(17); heap.insert(5); heap.insert(4); heap.insert(22); heap.remove(); //Sort array items in ascending order //not working.. heap.sortAscending(new int[5] { 5, 20, 11, 7, 8 }); Console.WriteLine("----------------------"); heap.sortDescending(new int[5] { 5, 20, 11, 7, 8 }); MaxHeap.heapify(new int[6] { 5, 3, 8, 4, 1, 2 }); MaxHeap maxHeap = new MaxHeap(); var kthLargest = maxHeap.getKthLargestNumber(new int[6] { 5, 3, 8, 4, 1, 2 }, 3); Console.WriteLine("Kth Largest number is :" + kthLargest); Console.WriteLine("-----------HeapExercise----------"); HeapExercise heapExercise = new HeapExercise(); var isMaxHeap = heapExercise.isMaxHeap(new int[6] { 8, 4, 5, 3, 10, 2 }); Console.WriteLine("Is this is a Max Heap -> { 5, 3, 8, 4, 1, 2 } :" + isMaxHeap); Console.WriteLine("-----------MinHeap----------"); MinHeap minHeap = new MinHeap(); minHeap.insert(30, "A"); minHeap.insert(3, "B"); minHeap.insert(60, "C"); minHeap.insert(1, "D"); minHeap.insert(10, "E"); //minHeap.insert(2, "F"); Console.WriteLine(minHeap.print()); Console.WriteLine("Removed value is from MinHeap is : " + minHeap.remove()); Console.WriteLine("-----------PriorityQueueWithMinHeap----------"); PriorityQueueWithMinHeap priorityQueueWithMinHeap = new PriorityQueueWithMinHeap(); priorityQueueWithMinHeap.add("Kavita", 5); priorityQueueWithMinHeap.add("Brother", 3); priorityQueueWithMinHeap.add("Mom", 1); priorityQueueWithMinHeap.add("Dad", 2); priorityQueueWithMinHeap.add("Brother", 3); Console.WriteLine(priorityQueueWithMinHeap.print()); Console.WriteLine("Value removed from Priority Queue using MinHeap is : " + priorityQueueWithMinHeap.remove()); Console.ReadLine(); }