You are viewing a single comment's thread. Return to all 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()); } }
Seems like cookies are disabled on this browser, please enable them to open this website
Queue using Two Stacks
You are viewing a single comment's thread. Return to all comments →
i don't really understand why it's asking to do it with 2 stacks