public static T[] HeapSort(T[] data) { T[] returnData = new T[data.Length]; HeapTree <T> heap = new HeapTree <T>(); for (int i = 0; i < data.Length; i++) { heap.Insert(data[i]); } for (int i = 0; i < data.Length; i++) { returnData[i] = heap.Pop(); } return(returnData); }
static void Main(string[] args) { HeapTree <int> tree = new HeapTree <int>(10); // insert should be: // 1 3 2 6 4 5 for (int i = 6; i > 0; i--) { tree.Insert(i); } // pop should be: // 2 3 5 6 4 int temp = tree.Pop(); ; Console.ReadKey(); }
static void Main(string[] args) { HeapTree <int> heap = new HeapTree <int>(); //heap.Insert(1); //heap.Insert(9); //heap.Insert(2); //heap.Insert(13); //heap.Insert(10); //heap.Insert(3); //heap.Insert(0); Random random = new Random(); for (int i = 0; i < 1000; i++) { heap.Insert(random.Next(0, 1000)); } while (heap.Count > 0) { Console.WriteLine(heap.Pop()); } }