Пример #1
0
        /// <summary>
        /// Takes input queue and pushes items onto stack.
        /// </summary>
        /// <returns> The stack containing queue items.</returns>
        /// <param name="Q">Original queue.</param>
        public LinkedStack <T> QueueToStack(LinkedQueue <T> Q)
        {
            LinkedStack <T> S       = new LinkedStack <T>();
            Node            current = Q.First;

            while (current.Next != null)
            {
                Node removed = current;
                S.Push(removed.Value);
                Q.Dequeue();
                current = current.Next;
            }
            return(S);
        }
Пример #2
0
        /// <summary>
        /// Takes input queue and pushes items onto stack.
        /// </summary>
        /// <returns>The stack with queue items.</returns>
        /// <param name="q">Original queue.</param>
        public LinkedStack <T> QueueToStack(LinkedQueue <T> q)
        {
            LinkedStack <T> s       = new LinkedStack <T>();
            Node            current = q.First;

            while (current.Next != null)
            {
                Node removed = current;
                s.Push(removed.Value);
                q.Dequeue();
                current = current.Next;
            }
            return(s);
        }
Пример #3
0
        static void Main(string[] args)
        {
            LinkedQueue <int> arrayQueue = new LinkedQueue <int>(3);

            arrayQueue.Enqueue(5);
            arrayQueue.Enqueue(6);
            arrayQueue.Enqueue(7);
            arrayQueue.Enqueue(8);
            arrayQueue.Enqueue(5);
            while (arrayQueue.Count != 0)
            {
                Console.WriteLine(arrayQueue.Dequeue());
            }
        }