Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. import CITS2200.*;
  2.  
  3. public class StackBlock implements Stack
  4. {
  5. int size;
  6. Object[] stackBlock;
  7.  
  8. public StackBlock(int s){
  9. this.stackBlock = new Object[s];
  10. this.size = 0;
  11. }
  12.  
  13. public boolean isEmpty(){
  14. if (this.size==0){
  15. return true;
  16. }
  17. return false;
  18. }
  19.  
  20. public boolean isFull(){
  21. if(this.size==this.stackBlock.length){
  22. return true;
  23. }
  24. return false;
  25. }
  26.  
  27. public void push(Object o){
  28. if(isFull()){
  29. throw new Overflow("StackBlock is full");
  30. }
  31. else{
  32. this.stackBlock[this.size] = o;
  33. this.size++;
  34. }
  35. }
  36.  
  37. public Object examine() {
  38. if (isEmpty()) {
  39. throw new Underflow("StackBlock is empty");
  40. } else {
  41. return this.stackBlock[this.size];
  42.  
  43. }
  44. }
  45.  
  46. public Object pop(){
  47. if (isEmpty()) {
  48. throw new Underflow("StackBlock is empty");
  49. } else {
  50. this.size--;
  51. return stackBlock[size];
  52. }
  53. }
  54.  
  55.  
  56.  
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement