fork download
  1. #include<iostream>
  2. #define SIZE 100
  3. using namespace std;
  4.  
  5. struct stack{
  6. int top;
  7. int arr[SIZE];
  8. };
  9.  
  10. void push(struct stack *s, int val){
  11. if(s->top<SIZE-1){
  12. s->top++;
  13. s->arr[s->top] = val;
  14. }else{
  15. cout<<"stack is full";
  16. }
  17. }
  18.  
  19. int pop(struct stack *s){
  20. if(s->top!=-1){
  21. int val = s->arr[s->top];
  22. s->top--;
  23. return val;
  24. }else{
  25. cout<<"stack is empty";
  26. }
  27. }
  28.  
  29. int main(){
  30. struct stack s;
  31. s.top = -1;
  32. push(&s, 10);
  33. push(&s, 20);
  34. push(&s, 30);
  35. push(&s, 40);
  36. push(&s, 50);
  37. push(&s, 60);
  38. pop(&s);
  39. pop(&s);
  40. push(&s, 70);
  41. pop(&s);
  42. pop(&s);
  43. pop(&s);
  44. push(&s, 80);
  45. cout<<pop(&s);
  46. }
  47.  
Success #stdin #stdout 0s 4580KB
stdin
Standard input is empty
stdout
80