private static void TestHeap(DHeapType type, int rank) { var fixture1 = new [] { 0, 0, 1, 2, 3, 4, 5, 5, 5, 6, 7, 8, 9 }; var fixture2 = new [] { 9, 9, 9, 2, 4, 5, 10, 15, 0, 8, 13, 19 }; SequenceUtils.Shuffle(fixture1); var heap = new DHeap<int>(fixture1, type, rank); foreach (var item in fixture2) { heap.Add(item); } var combined = fixture1.Concat(fixture2).ToArray(); combined = type == DHeapType.Max ? combined.OrderByDescending(a => a).ToArray() : combined.OrderBy(a => a).ToArray(); Assert.AreEqual(combined.Count(), heap.Count); foreach (var item in combined) { Assert.AreEqual(item, heap.GetPeak()); } Assert.AreEqual(0, heap.Count); }
static void Main(string[] args) { var heap = DHeap.Create(); while (true) { Console.Write("\nPress any key to continue...\n"); Console.Write("1)Добавить узел\n"); Console.Write("2)Удалить корень\n"); Console.Write("3)Отрисовка кучи\n"); int choise = Int32.Parse(Console.ReadLine()); switch (choise) { case 1: { Console.Write("Введите узел: "); var n = Int32.Parse(Console.ReadLine()); heap.Insert(n); break; } case 2: { heap.RemoveMin(); break; } case 3: { heap.Print(); break; } default: Console.Write("Плохой выбор\n"); break; } } }
/// <summary> /// Merges a DHeap<TKey, TValue> into this one. /// </summary> /// <param name="other">The DHeap<TKey, TValue> to merge into this one.</param> public void Merge(DHeap <TKey, TValue> other) { this.AddRange(other.heap); this.Heapify(); }