Exemple #1
0
        public int Dequeue()                        //remove front node from linked list
        {
            LLNode ouput = new LLNode();

            if (list.GetFront() != null)
            {
                ouput = list.GetFront();

                list.SetFront(list.GetFront().GetNext());
            }
            else
            {
                Console.WriteLine("NOTHING IN QUEUE");
            }

            return(ouput.GetData());
        }
Exemple #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();
        }