コード例 #1
0
        /// <summary>
        /// Sort Ascending then find media. Haha!!!
        /// </summary>
        /// <returns></returns>
        //public static T FindMedian(T[] inputArray)
        //{

        //}


        private static T[] SortFromMaxHeapDescending(MaxHeap <T> maxHeap)
        {
            T[] elementsToSort = new T[maxHeap.GetHeapCount()];

            int startIndex = 0;

            while (!maxHeap.IsEmpty())
            {
                elementsToSort[startIndex] = maxHeap.DeleteItem(0);
                startIndex++;
            }

            return(elementsToSort);
        }
コード例 #2
0
        public static T[] SortDescending(ReadOnlySpan <T> unsortedArray)
        {
            var heap = new MaxHeap <T>(unsortedArray);

            return(SortFromMaxHeapDescending(heap));
        }