Flashcards
Implement Stack using Queues
Cards in this deck (1)
- 1push(x) -- Push element x onto stack. pop() -- Removes the element on top of the stack. top() -- Get the top element. empty() -- Return whether the stack is empty.class MyStack {
Queue q = null;
/** Initialize your data structure here. */
public MyStack() {
q = new LinkedList<>();
}
/** Push element x onto stack. */
public void push(int x) {
q.add(x);
for( int i = 1; i
Information
- Description
- Flashcards on Implement Stack using Queues, created by Suhas S on 13/05/2018.
- Created by
- Suhas S
- Views
- 0
- Rating