Queue using Two Stacks

  • + 0 comments

    i don't really understand why it's asking to do it with 2 stacks

    class Solution {
        private static List<int> oneStack = new List<int>();
    
        static void Main(String[] args) {
            var q = int.Parse(Console.In.ReadLine()!.TrimEnd()); // number of queries
            for(var i=0; i<q; i++){
                var a = Console.In.ReadLine()!.TrimEnd().Split(" ").Select(x => int.Parse(x)).ToArray();
                var t = a[0];
                switch(t){
                    case 1:
                        enqueue(a[1]);
                        break;
                    case 2:
                        dequeue();
                        break;
                    case 3: 
                        print();
                        break;
                    default:
                        throw new Exception($"t={t}");
                }
            }
        }
    
        static void enqueue(int x){
            oneStack.Add(x);
        }
    
        static void dequeue(){
            oneStack = oneStack.Skip(1).ToList();
        }
    
        static void print(){
            Console.WriteLine(oneStack.First());
        }
    }