cStack.cpp 655 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include <iostream>
  2. #include "cStack.h"
  3. using namespace std;
  4. cStack::cStack () {top = 0;}
  5. cStack::~cStack () {
  6. //clean_stack ();
  7. }
  8. void cStack::push (double _var) {
  9. st [++top] = _var;
  10. }
  11. double cStack::pop () {
  12. double last_number = 9999999;
  13. last_number = st [top];
  14. st [top] = 0;
  15. top--;
  16. return last_number;
  17. }
  18. int cStack::stack_size () {
  19. return top;
  20. }
  21. void cStack::clean_stack () {
  22. for (int i = 0; i < MAX_STACK_SIZE; i++) {
  23. st [i] = 0;
  24. }
  25. top = 0;
  26. }
  27. void cStack::show_stack () {
  28. cout << "top = " << top << endl;
  29. for (int i = 0; i < MAX_STACK_SIZE; i++ ) {
  30. cout << "st" << i << " " << st [i] << " ";
  31. }
  32. cout << endl;
  33. }