/// <summary> /// BinaryHeap{T} 를 Ascending 정렬하여 반환합니다. /// </summary> /// <param name="list"></param> /// <param name="comparer"></param> /// <returns></returns> public static IList <T> Sort(IList <T> list, IComparer <T> comparer) { var result = new List <T>(); var heap = new BinaryHeap <T>(list, comparer); while (heap.Count > 0) { result.Insert(0, heap.PopRoot()); } return(result); }
public void InsertSerial() { var heap = new BinaryHeap <int>(); for (int i = 0; i < ItemCount; i++) { heap.Add(i); } int root = int.MaxValue; for (int i = 0; i < ItemCount; i++) { var item = heap.PopRoot(); root.Should().Be.GreaterThanOrEqualTo(item); root = item; } }
public void InsertRandom() { var heap = new BinaryHeap <int>(); const int maxValue = ItemCount * 100; for (int i = 0; i < ItemCount; i++) { heap.Add(Rnd.Next(1, maxValue)); } int root = int.MaxValue; for (int i = 0; i < ItemCount; i++) { var item = heap.PopRoot(); root.Should().Be.GreaterThanOrEqualTo(item); root = item; } }
public T Dequeue() { return(_heap.PopRoot()); }