fork download
  1. #include <iostream>
  2. using namespace std;
  3. #define MAX 101
  4. int stack_arr[MAX];
  5. int top=0;
  6. int isfull(){
  7. if(top==100){
  8. return true;
  9. }
  10. return false;
  11. }
  12. int isnull(){
  13. if(top==0){
  14. return true;
  15. }
  16. return false;
  17. }
  18. void push(int data){
  19. if(!isfull()){
  20. top++;
  21. stack_arr[top]=data;
  22. }
  23. }
  24. void pop(){
  25. if(!isnull()){
  26. top--;
  27. }
  28. }
  29. void display(){
  30. if(!isnull()){
  31. cout << stack_arr[top];
  32. }
  33. cout << "\n";
  34. }
  35. void print_full(){
  36. if(!isnull()){
  37. for(int i=top;i>0;i--){
  38. cout << stack_arr[i] << " ";
  39. }
  40. }
  41. cout << "\n";
  42. }
  43. int main() {
  44. push(2);
  45. push(3);
  46. print_full();
  47. push(4);
  48. print_full();
  49. push(5);
  50. print_full();
  51. }
  52.  
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
3 2 
4 3 2 
5 4 3 2