• + 2 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.

    //Write your code here
        List<char> charStack = new List<char>();
        List<char> charQueue = new List<char>();
        
        void pushCharacter(char ch) {
            charStack.Add(ch);
        }
        
        void enqueueCharacter(char ch) {
            charQueue.Add(ch);
        }
        
        char popCharacter() {
            char returnChar = charStack[charStack.Count - 1];
            charStack.RemoveAt(charStack.Count - 1);
            return returnChar;        
        }
        
        char dequeueCharacter() {
            char returnChar = charQueue[0];
            charQueue.RemoveAt(0);
            return returnChar;       
        }