We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
That's obviously the most logical solution, and also the one I arrived at first. But to understand the principles of Stack and Queue, FILO and FIFO, I thought it would be nice to create your own implementation of those patterns using Lists. So this is my take on that.
//Write your code hereList<char>charStack=newList<char>();List<char>charQueue=newList<char>();voidpushCharacter(charch){charStack.Add(ch);}voidenqueueCharacter(charch){charQueue.Add(ch);}charpopCharacter(){charreturnChar=charStack[charStack.Count-1];charStack.RemoveAt(charStack.Count-1);returnreturnChar;}chardequeueCharacter(){charreturnChar=charQueue[0];charQueue.RemoveAt(0);returnreturnChar;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 18: Queues and Stacks
You are viewing a single comment's thread. Return to all comments →
That's obviously the most logical solution, and also the one I arrived at first. But to understand the principles of Stack and Queue, FILO and FIFO, I thought it would be nice to create your own implementation of those patterns using Lists. So this is my take on that.