You are viewing a single comment's thread. Return to all comments →
To start in C#
using System; using System.Collections.Generic; using System.IO; class Solution { public class MyQueue<T> { Stack<T> stackNewestOnTop = new Stack<T>(); Stack<T> stackOldestOnTop = new Stack<T>(); public void Enqueue(T value) { // Push onto newest stack } public T Peek() { } public T Dequeue() { } } static void Main(String[] args) { MyQueue<int> queue = new MyQueue<int>(); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string[] line = Console.ReadLine().Split(' '); int operation = int.Parse(line[0]); if (operation == 1) { // enqueue queue.Enqueue(int.Parse(line[1])); } else if (operation == 2) { // dequeue queue.Dequeue(); } else if (operation == 3) { // print/peek Console.WriteLine(queue.Peek()); } } } }
Seems like cookies are disabled on this browser, please enable them to open this website
Queues: A Tale of Two Stacks
You are viewing a single comment's thread. Return to all comments →
To start in C#