Guest User

Untitled

a guest
Dec 18th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. class stack
  4. {
  5. private:
  6. int arr[5];
  7. int top;
  8. public:
  9. stack()
  10. {
  11. top = -1;
  12. }
  13. void push ( int v )
  14. {
  15. if ( top == 4 )
  16. { cout << "stack is full" << endl; }
  17. else
  18. {
  19. arr[++top] = v;
  20. cout << "data push successfully" << endl;
  21. }
  22. }
  23. int pop()
  24. {
  25. if ( top == -1 )
  26. {
  27. cout << "stack empty" << endl;
  28. return 0;
  29. }
  30. else
  31. { return arr[top--]; }
  32. }
  33. };
  34. int main()
  35. {
  36. stack s;
  37. s.push ( 10 );
  38. cout << s.pop() << endl;
  39. return 0;
  40. }
Add Comment
Please, Sign In to add comment