示例#1
0
        static void Main(string[] args)
        {
            LLNode ANode = new LLNode(4, null);
            LLNode BNode = new LLNode(1, null);
            LLNode CNode = new LLNode(7, null);
            LLNode DNode = new LLNode(3, null);
            LLNode ENode = new LLNode(5, null);
            LLNode FNode = new LLNode(0, null);
            //LLNode Temp = new LLNode(100);
            //testList.SetCurrent(Temp);
            LinkedQueue testQueue = new LinkedQueue();

            Console.WriteLine("Linked based queue assignment.");
            testQueue.Dequeue(); // TESTING on dequeue when the queue is empty
            Console.WriteLine("Enqueue Node A");
            testQueue.Enqueue(ANode);
            Console.WriteLine("Enqueue Node B");
            testQueue.Enqueue(BNode);
            testQueue.Peek();
            Console.WriteLine("Enqueue Node C");
            testQueue.Enqueue(CNode);
            Console.WriteLine("Enqueue Node D");
            testQueue.Enqueue(DNode);

            testQueue.PrintQueue();
            Console.WriteLine("######################################");
            testQueue.Dequeue();
            testQueue.Peek();
            testQueue.Dequeue();
            testQueue.Dequeue();
            testQueue.Dequeue();
            testQueue.Peek();
            Console.ReadKey();
        }
示例#2
0
        static void Main(string[] args)
        {
            LinkedQueue testQueue = new LinkedQueue(1, 2);          //create Queue with values 1 and 2

            Console.WriteLine("Queue created with 1, 2");
            Console.WriteLine();
            Console.WriteLine($"Current in Queue:{testQueue.Peek().GetData()}");
            Console.WriteLine();
            LLNode newBack = new LLNode(3);

            Console.WriteLine($"Adding to Queue:{newBack.GetData()}");
            testQueue.Enqueue(newBack);
            Console.WriteLine();
            Console.WriteLine($"Dequeuing:{testQueue.Dequeue()}");
            Console.WriteLine($"Current in Queue:{testQueue.Peek().GetData()}");
            Console.WriteLine();
            LLNode newBack2 = new LLNode(4);

            Console.WriteLine($"Adding to Queue:{newBack2.GetData()}");
            testQueue.Enqueue(newBack2);
            Console.WriteLine();

            while (testQueue.Peek() != null)
            {
                Console.WriteLine($"Dequeuing:{testQueue.Dequeue()}");
                if (testQueue.Peek() != null)
                {
                    Console.WriteLine($"Current in Queue:{testQueue.Peek().GetData()}");
                }
                else
                {
                    break;
                }
                Console.WriteLine();
            }

            Console.ReadKey();
        }