Esempio n. 1
0
        public void Sort(IList <T> collection)
        {
            var heap  = new BinaryHeap <T>(collection);
            int index = collection.Count - 1;

            while (heap.Count != 0)
            {
                var item = heap.ExtractMax();
                collection[index] = item;
                index--;
            }
        }
Esempio n. 2
0
        public void Sort(List <T> collection)
        {
            var heap  = new BinaryHeap <T>(collection.ToArray());
            int index = collection.Count - 1;

            while (heap.Count > 0)
            {
                var max = heap.ExtractMax();
                collection[index] = max;
                index--;
            }
        }
Esempio n. 3
0
        public void Sort(List <T> collection)
        {
            var heap = new BinaryHeap <T>(collection);

            List <T> elements = new List <T>(heap.Count);

            int position = heap.Count - 1;

            while (heap.Count > 0)
            {
                var maxElement = heap.ExtractMax();
                collection[position] = maxElement;
                position--;
            }
        }