Guest User

Untitled

a guest
Oct 22nd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Stack
  6. {
  7. private:
  8. int * Arr;
  9. int TOP, SIZE;
  10. public:
  11. Stack(unsigned int _size = 15)
  12. {
  13. Arr = new int[15];
  14. SIZE = _size;
  15. TOP = 0 ;
  16. }
  17. bool Push(int value)
  18. {
  19. if (TOP<SIZE)
  20. {
  21. Arr[TOP++]= value;
  22. return true;
  23. } else
  24. return false;
  25.  
  26. }
  27.  
  28. bool pop(int & val)
  29. {
  30. if (TOP-1 >= 0)
  31. {
  32. val = Arr[TOP--];
  33. return true;
  34. } else
  35. return false;
  36. }
  37. };
  38.  
  39. int main()
  40. {
  41. Stack T;
  42. for (int i =0 ; i < 15; i++)
  43. {
  44. if (T.Push(i))
  45. cout << i << endl;
  46. else
  47. cout << "No" << endl;
  48. }
  49. return 0;
  50. }
Add Comment
Please, Sign In to add comment