예제 #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter number of elements in max-heap");

            int count = int.Parse(Console.ReadLine());

            int[] maxHeap = new int[count];

            Console.WriteLine("Enter elements with enter");

            for(var i = 0; i < count; i++)
            {
                maxHeap[i] = int.Parse(Console.ReadLine());
            }

            Console.WriteLine("Enter k - index of k-th largest element");

            var k = int.Parse(Console.ReadLine());

            MaxHeap heap = new MaxHeap(maxHeap, k);

            var result = heap.FindMax();

            Console.WriteLine("Result: " + maxHeap[result]);

            Console.ReadKey();
        }
예제 #2
0
        static void Main(string[] args)
        {
            var numbers = new int[] { 5, 3, 8, 4, 1, 2 };

            MaxHeap.Heapify(numbers);

            foreach (var number in numbers)
            {
                Console.WriteLine(number);
            }
        }
예제 #3
0
        public static void Main1(string[] args)
        {
            MaxHeap <int> maxHeap = new MaxHeap <int>(5);

            maxHeap.Insert(1);
            maxHeap.Insert(2);
            maxHeap.Insert(3);
            maxHeap.Insert(4);
            maxHeap.Insert(5);

            maxHeap.Print();
        }
예제 #4
0
        static void Main(string[] args)
        {
            MaxHeap <int> maxheap = new MaxHeap <int>();

            maxheap.Add(2);
            maxheap.Add(1);
            maxheap.Add(10);
            maxheap.Add(11);
            maxheap.Add(22);
            maxheap.Add(-5);
            maxheap.Add(4);


            Console.WriteLine(maxheap.PeekMax());
        }