public static T[] Heapsort <T>(T[] array, SortDirection direction) where T : IComparable <T> { IBinaryHeap <T> heap; if (direction == SortDirection.Ascending) { heap = new MaxBinaryHeap <T>(array); } else { heap = new MinBinaryHeap <T>(array); } T[] result = new T[array.Length]; int counter = 0; while (heap.Length != 0) { result[counter] = heap.ReleaseValue(); counter++; } return(result); }
public static void Heapsort <T>(ref List <T> array, SortDirection direction) where T : IComparable <T> { IBinaryHeap <T> heap; if (direction == SortDirection.Ascending) { heap = new MaxBinaryHeap <T>(array.ToArray()); } else { heap = new MinBinaryHeap <T>(array.ToArray()); } int counter = 0; while (heap.Length != 0) { array[counter] = heap.ReleaseValue(); counter++; } }