Пример #1
0
        public void Main()
        {
            int  value, value2;
            Heap theHeap = new Heap(31);
            bool success;

            theHeap.Insert(70);
            theHeap.Insert(40);
            theHeap.Insert(50);
            theHeap.Insert(20);
            theHeap.Insert(60);
            theHeap.Insert(100);
            theHeap.Insert(80);
            theHeap.Insert(30);
            theHeap.Insert(10);
            theHeap.Insert(90);

            var choise = "s";  // s-enter, i-insert, r-remove, c-change priority

            switch (choise)
            {
            case "s":
                theHeap.Display();
                break;

            case "i":
                var newValue = (new Random()).Next(1, 100);
                success = theHeap.Insert(newValue);
                if (!success)
                {
                    Console.WriteLine("Can't insert: the heap is full");
                    break;
                }
                break;

            case "r":
                if (!theHeap.IsEmpty())
                {
                    theHeap.Remove();
                }
                else
                {
                    Console.WriteLine("Can't remove: the heap full");
                }
                break;

            case "c":
                value   = (new Random()).Next(1, 5);
                value2  = (new Random()).Next(2, 3);
                success = theHeap.Change(value, value2);
                if (!success)
                {
                    Console.WriteLine("Invalid index");
                }
                break;

            default:
                break;
            }
        }