Exemple #1
0
        public static T[] HeapSort <T>(T[] A) where T : IComparable <T>
        {
            BinaryHeap <T> heap = new BinaryHeap <T>(A);

            Console.WriteLine();
            T[] sorted = new T[heap.Count];
            int i      = 0;

            while (heap.Count != 0)
            {
                sorted[i++] = heap.Remove();
            }
            return(sorted);
        }
Exemple #2
0
        public static int[] HeapSort(int[] A)
        {
            BinaryHeap <int> heap = new BinaryHeap <int>(A, HeapType.Max);

            Console.WriteLine(heap.Contains(8));
            Console.WriteLine();
            int[] sorted = new int[heap.Count];
            int   i      = 0;

            while (heap.Count != 0)
            {
                sorted[i++] = heap.Remove();
            }
            return(sorted);
        }