Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import CITS2200.*;
- public class StackBlock implements Stack
- {
- int size;
- Object[] stackBlock;
- public StackBlock(int s){
- this.stackBlock = new Object[s];
- this.size = 0;
- }
- public boolean isEmpty(){
- if (this.size==0){
- return true;
- }
- return false;
- }
- public boolean isFull(){
- if(this.size==this.stackBlock.length){
- return true;
- }
- return false;
- }
- public void push(Object o){
- if(isFull()){
- throw new Overflow("StackBlock is full");
- }
- else{
- this.stackBlock[this.size] = o;
- this.size++;
- }
- }
- public Object examine() {
- if (isEmpty()) {
- throw new Underflow("StackBlock is empty");
- } else {
- return this.stackBlock[this.size];
- }
- }
- public Object pop(){
- if (isEmpty()) {
- throw new Underflow("StackBlock is empty");
- } else {
- this.size--;
- return stackBlock[size];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement