Implement a queue using two stacks

Implement a queue using two stacks. This means that when you enqueue an item, it goes onto one of the stacks, and when you dequeue an item, it comes off of the other stack.

Problem

Implement a queue using two stacks.
Example input:
enqueue(1)
enqueue(2)
enqueue(3)
Example output:
1
2
3

Solution

This solution is in C#. Our A.I. can create solutions in multiple languages.
by kayakane
using System;
using System.Collections.Generic;

namespace InterviewPreperationGuide.Core.CrackingTheCodingInterview.c3q6 {
    public class Solution {
        public void Init () {
            Console.WriteLine ();
        }
    }

    public class MyQueue<T> {
        private Stack<T> stackNewestOnTop = new Stack<T> ();
        private Stack<T> stackOldestOnTop = new Stack<T> ();

        public void Enqueue (T value) {
            stackNewestOnTop.Push (value);
        }

        public T Peek () {
            ShiftStacks ();
            return stackOldestOnTop.Peek ();
        }

        public T Dequeue () {
            ShiftStacks ();
            return stackOldestOnTop.Pop ();
        }

        private void ShiftStacks () {
            if (stackOldestOnTop.Count == 0) {
                while (stackNewestOnTop.Count > 0) {
                    stackOldestOnTop.Push (stackNewestOnTop.Pop ());
                } }
        }
    }
}

A.I. Evaluation of the Solution

The candidate's solution correctly implements a queue using two stacks. However, the code could be more concise. For example, the ShiftStacks method can be simplified. Additionally, the candidate does not provide any comments explaining the code.

Evaluated at: 2022-11-29 12:15:39