Ejemplo n.º 1
0
        public void CanBuildHeap()
        {
            var t1 = new[] { 4, 1, 3, 2, 16, 9, 10, 14, 8, 7 };

            var heap = new Heap()
            {
                Elements = t1,
                HeapSize = t1.Length
            };

            MyHeapSorter.BuildMaxHeap(heap);
        }
Ejemplo n.º 2
0
        public void CanMaxHeapify(int[] inputElements, int heapSize, int startIndex, int[] expected)
        {
            var heap = new Heap()
            {
                Elements = inputElements,
                HeapSize = heapSize
            };

            MyHeapSorter.MaxHeapify(heap, startIndex);

            Assert.Equal(expected, heap.Elements);
        }
Ejemplo n.º 3
0
        public void CanSort()
        {
            var t1 = new[] { 4, 1, 3, 2, 16 };

            var heap = new Heap()
            {
                Elements = t1,
                HeapSize = t1.Length
            };

            var result = MyHeapSorter.HeapSort(heap).ToArray();

            Assert.Equal(new[] { 16, 4, 3, 2, 1 }, result);
        }