Stack
overflow
Implement Queue using Stack
class MyQueue {
Stack stack;
int top;
public MyQueue() {
stack = new Stack();
}
public void push(int x) {
Stack temp = new Stack();
if (stack.isEmpty()) {
stack.push(x);
} else {
while (!stack.isEmpty()) {
temp.push(stack.pop());
}
stack.push(x);
while (!temp.isEmpty()) {
stack.push(temp.pop());
}
}
}
public int pop() {
return (int) stack.pop();
}
public int peek() {
return (int) stack.peek();
}
public boolean empty() {
return stack.isEmpty();
}
}Balanced Parenthesis
Two stacks in an array(Useless Question)
K Stacks in an array(UseLess Question)
Stock Span Problem
Previous Greater Element
Next Greater Element
Largest Rectangular Area in a Histogram (Part 1)
Largest Rectangular Area in a Histogram (Part 2)
Largest Rectangle with all 1's (in a matrix)
Stack with getMin() in O(1)
Design a Stack with getMin() in O(1) Space
Assuming all Elements Positive
Handles Negatives
Last updated