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