static void Main(string[] args) { //var heap = new HeapTree<Person>(new PersonNameLengthComparer()); var heap = new HeapTree <Person>(Comparer <Person> .Create((x, y) => x.Age.CompareTo(y.Age))); heap.Add(new Person("Jimothy", 55)); heap.Add(new Person("Jimbo", 35)); heap.Add(new Person("Jim", 8)); heap.Add(new Person("Z", 89)); heap.Add(new Person("Y", 150)); //var heap = new HeapTree<int>(); //Random gen = new Random(42); //for (int i = 0; i < 5; i++) //{ // heap.Add(10 - i); //} foreach (Person person in heap.HeapSort()) { Console.WriteLine($"{person.Name}, {person.Age}"); } //heap.Pop(); //heap.Add(heap.Pop()); }
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()); } }