Ejemplo n.º 1
0
        private static string DumpHeap <T>(LeftistHeap <T> .Heap heap) where T : IComparable <T>
        {
            if (LeftistHeap <T> .IsEmpty(heap))
            {
                return("\u2205");
            }

            var results = new StringBuilder();

            if (!LeftistHeap <T> .IsEmpty(heap.A))
            {
                results.Append(DumpHeap(heap.A));
            }

            results.Append(heap.X);
            //results.Append(" [");
            //results.Append(heap.r);
            //results.Append("]");
            results.Append(", ");

            if (!LeftistHeap <T> .IsEmpty(heap.B))
            {
                results.Append(DumpHeap(heap.B));
            }

            return(results.ToString());
        }
Ejemplo n.º 2
0
        public void SingleIsEmptyTest()
        {
            var heap = LeftistHeap <int> .Empty;

            heap = LeftistHeap <int> .Insert(2, heap);

            Assert.IsFalse(LeftistHeap <int> .IsEmpty(heap));
        }
Ejemplo n.º 3
0
        public void SingleDeleteMinTest()
        {
            var heap = LeftistHeap <int> .Empty;

            heap = LeftistHeap <int> .Insert(2, heap);

            heap = LeftistHeap <int> .DeleteMin(heap);

            Assert.IsTrue(LeftistHeap <int> .IsEmpty(heap));
        }
Ejemplo n.º 4
0
        public void DeleteLotsOfMinsTest()
        {
            var random = new Random(3456);
            var heap   = LeftistHeap <int> .Empty;

            for (var i = 0; i < 100; i++)
            {
                heap = LeftistHeap <int> .Insert(random.Next(100), heap);
            }
            var last  = 0;
            var count = 0;

            while (!LeftistHeap <int> .IsEmpty(heap))
            {
                var next = LeftistHeap <int> .FindMin(heap);

                heap = LeftistHeap <int> .DeleteMin(heap);

                Assert.IsTrue(last <= next);
                last = next;
                count++;
            }
            Assert.AreEqual(100, count);
        }
Ejemplo n.º 5
0
        public void EmptyIsEmptyTest()
        {
            var heap = LeftistHeap <int> .Empty;

            Assert.IsTrue(LeftistHeap <int> .IsEmpty(heap));
        }