fork download
  1. #include <stdio.h>
  2.  
  3. #define STACK_SIZE 100
  4. int stack[STACK_SIZE];
  5. int sp=0;
  6.  
  7. int push(int x){
  8. if(sp==STACK_SIZE)
  9. return -1;
  10. stack[sp]=x;
  11. sp++;
  12. return 1;
  13. }
  14.  
  15. int pop(void){
  16. if(sp==0)
  17. return -1;
  18. sp--;
  19. return stack[sp];
  20. }
  21.  
  22. int main(void) {
  23. int data[]={11,12,13,14,15};
  24. int n=5;
  25. printf("data[] = ");
  26. for(int i=0;i<n;i++){
  27. printf("%d ",data[i]);
  28. }
  29. printf("\n");
  30. printf("push & pop\n");
  31. for(int i=0;i<n;i++){
  32. push(data[i]);
  33. }
  34. for(int i=0;i<n;i++){
  35. data[i]=pop();
  36. }
  37. printf("data[] = ");
  38. for(int i=0;i<n;i++){
  39. printf("%d ",data[i]);
  40. }
  41. printf("\n");
  42.  
  43. // your code goes here
  44. return 0;
  45. }
  46.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
data[] = 11 12 13 14 15 
push & pop
data[] = 15 14 13 12 11