Esempio n. 1
0
        public static void Main(string[] args)
        {
            // Simple Demo
            LinkedQueue <int> queue = new LinkedQueue <int>();

            queue.Enqueue(1);
            queue.Enqueue(2);
            queue.Enqueue(3);
            queue.Enqueue(4);
            Console.WriteLine(queue.ToString()); // outputs 1234
            Console.WriteLine();

            int dequeued = queue.Dequeue();

            Console.WriteLine(dequeued);         // outputs 1
            Console.WriteLine(queue.ToString()); // outputs 234
            Console.WriteLine();

            queue.Enqueue(5);
            Console.WriteLine(queue.ToString()); // outputs 2345
            Console.WriteLine();

            // I've also made unit tests that test everything in the queue.
        }
Esempio n. 2
0
        /// <summary>
        /// Makes a deep copy of the queue
        /// </summary>
        /// <returns>A deep copy of the queue</returns>
        public object Clone()
        {
            LinkedQueue <T> clone = new LinkedQueue <T>();

            Node currentNode = this.front;

            while (currentNode != null)
            {
                // We have non-empty queue
                clone.Enqueue(currentNode.Value);
                currentNode = currentNode.Next;
            }

            return(clone);
        }