Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Stack {
- private int size;
- private int top;
- private String[] stack;
- public Stack(int size) {
- this.size = size;
- stack = new String[size];
- top = -1;
- }
- public int getSize() {
- return size;
- }
- public boolean isEmpty(){
- return (top==-1);
- }
- public boolean isFull(){
- return (top==size-1);
- }
- public void push(String item) {
- if(isFull()) {
- Util.print("Stack is full");
- }
- stack[++top] = item;
- }
- public String pop() {
- if(isEmpty()) {
- Util.print("The stack is empty");
- return "";
- }
- return stack[top--];
- }
- public void reset() {
- for(int i=0; i<getSize(); i++) {
- stack[i] = "";
- }
- top = -1;
- }
- public void print(){
- for(int i=0; i<getSize(); i++) {
- Util.print(stack[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement