logo CodeStepByStep logo

Mystery1

Language/Type: C# stacks and queues

Write the output produced when the following method is passed each of the following stacks:

public static void Mystery1(Stack<int> s)
{
    Queue<int> q = new Queue<int>();
    while (s.Count != 0)
    {
        q.Enqueue(s.Peek());
        q.Enqueue(s.Pop());
    }
    while (q.Count != 0)
    {
        s.Push(q.Peek());
        q.Dequeue();
    }
    Console.WriteLine(s);
}
{2, 3, 1}
{42, -1, 4, 15, 9}
{30, 20, 10, 70, 50, 40}

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.