Exemplo n.º 1
0
 /// <summary>
 /// pass in stacks returns to console the value of first input in first input out
 /// wrapped in try catch block so if error is thrown will catch it and return message to user.
 /// </summary>
 /// <param name="myQueueWithStacks"></param>
 public static void TestDequeue(QueueWithTwoStacks myQueueWithStacks)
 {
     //make try catch to capture excetion from both stacks being empty
     try
     {
         Console.WriteLine(myQueueWithStacks.Dequeue().Value);
         Console.ReadLine();
     }
     catch (Exception)
     {
         Console.WriteLine("both stacks are empty nothing to dequeue");
         Console.ReadLine();
     }
 }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            QueueWithTwoStacks <char> queue = new QueueWithTwoStacks <char>();

            queue.Enqueue('a');
            queue.Enqueue('b');
            queue.Enqueue('c');

            char head = queue.Dequeue();

            Test(head, 'a');

            head = queue.Dequeue();
            Test(head, 'b');

            queue.Enqueue('d');
            head = queue.Dequeue();
            Test(head, 'c');

            queue.Enqueue('e');
            head = queue.Dequeue();
            Test(head, 'd');

            head = queue.Dequeue();
            Test(head, 'e');

            try
            {
                head = queue.Dequeue();
                Console.WriteLine("Test failed.");
            }
            catch (InvalidOperationException)
            {
                Console.WriteLine("Test passed.");
            }
        }