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.
Day 18: Queues and Stacks
Day 18: Queues and Stacks
+ 25 comments pretty simple in python3:
class Solution: def __init__(self): self.mystack = list() self.myqueue = list() return(None) def pushCharacter(self, char): self.mystack.append(char) def popCharacter(self): return(self.mystack.pop(-1)) def enqueueCharacter(self, char): self.myqueue.append(char) def dequeueCharacter(self): return(self.myqueue.pop(0))
+ 14 comments Here is my solution :
Stack<Character> stack = new Stack<>(); Queue<Character> queue = new LinkedList<>(); void pushCharacter(Character ch) { stack.push(ch); } void enqueueCharacter(char ch) { queue.add(ch); } char popCharacter(){ return stack.pop(); } char dequeueCharacter() { return queue.remove(); }
+ 6 comments My solution in c++, hope to help you
#include <iostream> #include <stack> #include <queue> using namespace std; class Solution { //Write your code here stack<char> s; queue<char> q; public: void pushCharacter(char i) { s.push(i); } void enqueueCharacter(char i) { q.push(i); } char popCharacter() { char temp = s.top(); s.pop(); return temp; } char dequeueCharacter() { char temp = q.front(); q.pop(); return temp; } };
+ 3 comments Java solution - passes 100% of test cases
From my HackerRank solutions.
Stack<Character> stack = new Stack<>(); Queue<Character> queue = new LinkedList<>(); void pushCharacter(char ch) { stack.push(ch); } void enqueueCharacter(char ch) { queue.add(ch); } char popCharacter() { return stack.pop(); } char dequeueCharacter() { return queue.remove(); }
Let me know if you have any questions.
+ 0 comments Python 3
class Solution: def __init__(self): self.stack, self.queue = [], [] def pushCharacter(self,a): self.stack.append(a) def popCharacter(self): return self.stack.pop() def enqueueCharacter(self,a): self.queue.append(a) def dequeueCharacter(self): return self.queue.pop(0)
Load more conversations
Sort 618 Discussions, By:
Please Login in order to post a comment