static void Main(string[] args) { /* * 60 * 40 50 * 20 10 30 */ BinaryMaxHeap bhMax = new BinaryMaxHeap(); bhMax.Insert(50); bhMax.Insert(40); bhMax.Insert(30); bhMax.Insert(20); bhMax.Insert(10); bhMax.Insert(60); //Remove 60 bhMax.ExtractMax(); BinaryMinHeap bhMin = new BinaryMinHeap(); bhMin.Insert(20); bhMin.Insert(30); bhMin.Insert(40); bhMin.Insert(50); bhMin.Insert(60); bhMin.Insert(70); bhMin.Insert(80); bhMin.Insert(90); bhMin.Insert(100); bhMin.Insert(10); //Remove 60 bhMin.ExtractMin(); }
private static void HeapSort(int[] array) { var heap = new BinaryMinHeap <int>(array.Length); foreach (var item in array) { heap.Add(item); } for (int i = 0; i < array.Length; i++) { array[i] = heap.RemoveMin(); } }
static void Main(string[] args) { BinaryMinHeap minHeap = new BinaryMinHeap(11); minHeap.Insert(3); minHeap.Insert(5); minHeap.Insert(1); minHeap.Insert(6); minHeap.Insert(8); minHeap.Insert(9); Console.WriteLine("Heap size: " + minHeap.HeapSize); Console.WriteLine("Minimum element of heap: " + minHeap.GetMin()); Console.WriteLine("Extracting minimum element: " + minHeap.ExtractMin()); Console.WriteLine("Minimum element of heap: " + minHeap.GetMin()); Console.WriteLine("Deleting element from heap: "); minHeap.Delete(3); Console.WriteLine("Heap size: " + minHeap.HeapSize); Console.WriteLine("Minimum element of heap: " + minHeap.GetMin()); Console.ReadKey(); }