Exemplo n.º 1
0
        public static void IsMaxHeap <T>(IHeap <T> heap)
            where T : IComparable <T>
        {
            var heapList = heap.ToList();

            for (int i = 0; i < heap.Count; i++)
            {
                if (2 * i < heap.Count)
                {
                    Assert.True(heapList[i].CompareTo(heapList[2 * i]) >= 0,
                                $"Value {heapList[i]} at index {i} is less than {heapList[2 * i]} at index {2 * 1}");
                }
                if ((2 * i) + 1 < heap.Count)
                {
                    Assert.True(heapList[i].CompareTo(heapList[(2 * i) + 1]) >= 0,
                                $"Value {heapList[i]} at index {i} is less than {heapList[(2 * i) + 1]} at index {(2 * i) + 1}");
                }
            }
        }