Beispiel #1
0
        public void Print()
        {
            DynArrayQueue Queue = new DynArrayQueue();

            Queue.Enqueue(Current);
            while (Queue.Count != 0)
            {
                TreeNode CurrentNode = (TreeNode)Queue.Dequeue();
                Console.WriteLine(CurrentNode.Value);
                Queue.Enqueue(CurrentNode.LeftChildren);
                Queue.Enqueue(CurrentNode.RightChildren);
            }
        }
Beispiel #2
0
        public MainWindow()
        {
            //************************************CODE RELATED TO VISUALIZATION************************************//
            //Here you'll see an example where we visualize a stack
            //Your as far as the visualization is concerned, is to splice in your Deque as a queue
            //Note: make the visualization for the queue a horizontal drawing (mentally, we picture stacks as vertical, and queues as
            //Horizontal. When you do that, also change the button from saying Push and Pop, to Enqueue and Dequeue.

            //Remove this sample code for the stack before submitting.
            //Inserting values for stack
            d.AddFront("Start");
            d.AddFront(400);
            d.AddFront(500);
            InitializeComponent();

            //This is where we register a "callback". Callbacks are basically functions that take executable
            //code as input. Well, if that sounds like hocus pocus, don't worry about it.
            //All you need to understand is that there are these things called eventHandlers i.e. functions
            //that are called when an event happens. Such as when you click your mouse, when you drag your mouse etc.
            //Here we are referring to the "click" event on the push and pop buttons
            //So where are the popBtn and PushBtn names defined?
            RemoveFrontBtn.Click += popBtn_Click; //Look in the MainWindow.xaml file, you'll see a attribute called x:name inside a Button tag
            AddFrontBtn.Click    += pushBtn_Click;
            AddEndBtn.Click      += AddEnd_Click;
            RemoveEndBtn.Click   += RemoveEnd_Click;
            drawStructure();


            //************************************CODE RELATED TO Dynamic Array Based Queue************************************//
            //Declare a dynamic array based queue and do a few Enqueue and Dequeue operations
            var myQueue = new DynArrayQueue();

            myQueue.Enqueue(1);
            myQueue.Print();
            myQueue.Enqueue(3);
            myQueue.Print();
            myQueue.Enqueue(5);
            myQueue.Print();
            myQueue.Enqueue(7);
            myQueue.Print();
            myQueue.Enqueue(9);
            myQueue.Print();
            myQueue.Enqueue(11);
            myQueue.Print();
            myQueue.Enqueue(9);
            myQueue.Print();
            myQueue.Enqueue(7);
            myQueue.Print();
            myQueue.Enqueue(5);
            myQueue.Print();
            myQueue.Enqueue(3);
            myQueue.Print();
            myQueue.Enqueue(1);
            myQueue.Print();

            myQueue.Dequeue();
            myQueue.Print();
            myQueue.Dequeue();
            myQueue.Print();

            myQueue.Enqueue(2);
            myQueue.Print();
            myQueue.Enqueue(4);
            myQueue.Print();
            myQueue.Dequeue();
            myQueue.Print();
            myQueue.Enqueue(6);
            myQueue.Print();
            myQueue.Dequeue();
            myQueue.Print();
            myQueue.Enqueue(8);
            myQueue.Print();

            myQueue.Dequeue();
            myQueue.Print();
            myQueue.Dequeue();
            myQueue.Print();
            myQueue.Dequeue();
            myQueue.Print();
            myQueue.Dequeue();
            myQueue.Print();
            myQueue.Dequeue();
            myQueue.Print();
            myQueue.Dequeue();
            myQueue.Print();
            myQueue.Dequeue();
            myQueue.Print();
            myQueue.Dequeue();
            myQueue.Print();
            myQueue.Dequeue();
            myQueue.Print();
            myQueue.Dequeue();
            myQueue.Print();
            myQueue.Dequeue();
            myQueue.Print();
            myQueue.Dequeue();
            myQueue.Print();
            myQueue.Dequeue();
            myQueue.Print();
            myQueue.Dequeue();
            myQueue.Print();
            myQueue.Dequeue();
            myQueue.Print();
            myQueue.Dequeue();
            myQueue.Print();
            myQueue.Dequeue();
            myQueue.Print();
            myQueue.Dequeue();
            myQueue.Print();
            myQueue.Dequeue();
            myQueue.Print();
            myQueue.Dequeue();
            myQueue.Print();

            //************************************CODE RELATED TO TREE************************************//
            //Create a tree with at least 5 nodes. Ensure that the tree has at least 3 levels (say 0 1 and 2)
            //Print out a breadth first traversal of the tree
            //If you can hook into the visualizer, that'd be awesome and worth 2% extra credit
            var t = new Tree();

            t.Add(3);
            t.Print();
            t.Add(1);
            t.Print();
            t.Add(4);
            t.Print();
            t.Add(5);
            t.Print();
            t.Add(9);
            t.Print();
            t.Add(8);
            t.Print();
            t.Add(7);
            t.Print();
            t.Add(2);
            t.Print();
            t.Add(9);
            t.Print();
        }