function that inserts an element into stack.
| 11 | |
| 12 | //function that inserts an element into stack. |
| 13 | void insert(char x) |
| 14 | { |
| 15 | |
| 16 | if(st.size() == 0) st.push(x); |
| 17 | |
| 18 | else |
| 19 | { //take out the topmost element, pop it and recursively call the function |
| 20 | char a = st.top(); |
| 21 | st.pop(); |
| 22 | insert(x); |
| 23 | |
| 24 | |
| 25 | // when inserted at the bottom then push items in stack |
| 26 | st.push(a); |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | // function that reverses the given stack |
| 31 | void reverse() |