Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Stk implements IStk {
- public final int MAXSIZE =100;
- private int top;
- private int bot;
- private int front;
- private int rear;
- private int maxStk;
- private char items [];
- public Stk ()
- {
- this.front=0;
- this.rear=0;
- this.maxStk=0;
- this.items = new char [MAXSIZE];
- }
- public Stk(int max)
- {
- this.maxStk = max+1;
- this.front = maxStk - 1;
- this.rear = maxStk - 1;
- this.items = new char [max];
- }
- public boolean isFull ()
- {
- // WRAP AROUND
- return ( (this.top + 1) % this.maxStk == this.bot );
- }
- public boolean isEmpty ()
- {
- return ( this.bot == this.top );
- }
- public void push (char item)
- {
- if (!isFull())
- { this.top = (this.top+1) % this.maxStk;
- this.items[top] = item;
- }
- else
- System.out.println ("Tried to insert into full stack.");
- }
- public char pop ()
- {
- char item;
- if (!isEmpty())
- {
- item = this.items[top];
- this.top = (this.top-1) % this.maxStk;
- return item;
- }
- else {
- System.out.println ("Tried to remove from empty stack.");
- return 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement