1
0

stack.cpp 526 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // stack.cpp -- Stack member functions
  2. #include "stack.h"
  3. Stack::Stack() // create an empty stack
  4. {
  5. top = 0;
  6. }
  7. bool Stack::isempty() const
  8. {
  9. return top == 0;
  10. }
  11. bool Stack::isfull() const
  12. {
  13. return top == MAX;
  14. }
  15. bool Stack::push(const Item & item)
  16. {
  17. if (top < MAX)
  18. {
  19. items[top++] = item;
  20. return true;
  21. }
  22. else
  23. return false;
  24. }
  25. bool Stack::pop(Item & item)
  26. {
  27. if (top > 0)
  28. {
  29. item = items[--top];
  30. return true;
  31. }
  32. else
  33. return false;
  34. }