Exemple #1
0
        public void PopMaintainsHeapProperty()
        {
            IntBinaryMaxHeap heap = new IntBinaryMaxHeap();

            heap.Push(5);
            heap.Push(10);
            heap.Push(20);
            Assert.Equal(20, heap.Pop());
            Assert.Equal(10, heap.Pop());
            Assert.Equal(5, heap.Pop());
            Assert.Equal(0, heap.Count);
        }
Exemple #2
0
        public void PopBasics()
        {
            IntBinaryMaxHeap heap = new IntBinaryMaxHeap();

            heap.Push(5);
            Assert.Equal(1, heap.Count);
            Assert.Null(heap.Root.Parent);
            Assert.Null(heap.Root.Left);
            Assert.Null(heap.Root.Right);

            Assert.Equal(5, heap.Pop());
            Assert.Equal(0, heap.Count);
            Assert.Null(heap.Root);
        }
Exemple #3
0
        public void PopMaintainsHeapProperty02()
        {
            IntBinaryMaxHeap heap = new IntBinaryMaxHeap();

            heap.Push(5);
            heap.Push(10);
            heap.Push(20);
            heap.Push(99);
            heap.Push(35);
            heap.Push(777);
            heap.Push(1);
            Assert.Equal(777, heap.Pop());
            Assert.Equal(99, heap.Pop());
            Assert.Equal(35, heap.Pop());
            Assert.Equal(20, heap.Pop());
            Assert.Equal(10, heap.Pop());
            Assert.Equal(5, heap.Pop());
            Assert.Equal(1, heap.Pop());
            Assert.Equal(0, heap.Count);
        }