Lets Create Our Own Custom Stack.

 package sorting;


public class IntStack {


private Object[] stack;

private int top;

private int size;


public IntStack() {

top = -1;

size = 2;

stack = new Object[2];

}


public IntStack(int size) {

top = -1;

this.size = size;

stack = new Object[this.size];

}


public boolean push(Object item) {

if (!isFull()) {

top++;

stack[top] = item;

return true;

} else {

return false;

}

}


public Object pop() {

return stack[top--];


}


public boolean isEmpty() {

return (top == -1);

}


private boolean isFull() {

return (top == stack.length - 1);

}

}

Comments

Popular posts from this blog

3 Lines of Code And You Can Download Your Favourite Youtube Video.

Leetcode Problem(Easy) Roman to Integer

Leetcode : (Find Minimum in Rotated Sorted Array)