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()); }
public void SingleIsEmptyTest() { var heap = LeftistHeap <int> .Empty; heap = LeftistHeap <int> .Insert(2, heap); Assert.IsFalse(LeftistHeap <int> .IsEmpty(heap)); }
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)); }
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); }
public void EmptyIsEmptyTest() { var heap = LeftistHeap <int> .Empty; Assert.IsTrue(LeftistHeap <int> .IsEmpty(heap)); }