fork download
  1. #include <iostream>
  2. #include <string.h>
  3. using namespace std;
  4.  
  5. char arr[20] = {0};
  6. int top = -1;
  7.  
  8. void push(char a)
  9. {
  10. arr[++top] = a;
  11. }
  12.  
  13. char pop()
  14. {
  15. if(top == -1) return '\0';
  16. return arr[top--];
  17. }
  18.  
  19. void insertatbottom(char op)
  20. {
  21. char op2 = pop();
  22. if(op2 =='\0') { push(op); return ;}
  23. insertatbottom(op);
  24. push(op2);
  25. }
  26.  
  27. void reverse()
  28. {
  29. char op = pop();
  30. if(op =='\0') return;
  31. reverse();
  32. insertatbottom(op);
  33. }
  34.  
  35. int main() {
  36. // your code goes here
  37. push('a');
  38. push('b');
  39. push('c');
  40. cout<<arr[2]<<arr[1]<<arr[0];
  41. reverse();
  42. cout<<arr[2]<<arr[1]<<arr[0];
  43. return 0;
  44. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
cbaabc