Esempio n. 1
0
        static void TestHeap()
        {
            var heap = new BinaryHeap <int>
            {
                3,
                8,
                5,
                6,
                4,
                10
            };
            int value = heap.Remove();

            Console.WriteLine(value);
        }
Esempio n. 2
0
        public void BinaryHeapSortsArray()
        {
            var testCollection = TestUtils.GetUnsortedCharArray();
            var heap           = new BinaryHeap();

            for (int i = 0; i < testCollection.Length; i++)
            {
                heap.Push(testCollection[i]);
            }

            IComparable[] result = new IComparable[testCollection.Length];
            for (int i = 0; i < testCollection.Length; i++)
            {
                result[i] = heap.Pop();
            }

            Assert.True(TestUtils.IsSorted(result));
            Assert.True(TestUtils.AreEqual(testCollection, result));
        }
Esempio n. 3
0
        //Demo: add and remove
        public static void Demo()
        {
            var heap = new BinaryHeap(50);

            int[] a = { 83, 25, 4, 92, 80, 70, 35, 29, 16, 35 };
            foreach (var i in a)
            {
                heap.Add(i);
            }
            heap.Show();


            Console.WriteLine(heap.isVerified());
            for (int i = 0; i != 5; ++i)
            {
                heap.RemoveLargest();
                heap.Show();
                Console.WriteLine(heap.isVerified());
            }
        }
Esempio n. 4
0
 public PriorityQueue()
 {
     _heap = new BinaryHeap <QueueEntry <T> >();
 }