diff --git a/Stack/Reverse_Stack.cpp b/Stack/Reverse_Stack.cpp new file mode 100644 index 0000000..66919a3 --- /dev/null +++ b/Stack/Reverse_Stack.cpp @@ -0,0 +1,45 @@ +#include +#include +using namespace std; + +void insertAtbottom(stack &s, int data){ + if(s.empty()){ + s.push(data); + return; + } + //rec case + int temp = s.top(); + s.pop(); + + insertAtbottom(s,data); + s.push(temp); +} + +void reverse(stack &s){ + if (s.empty()){ + return; + } + int t = s.top(); + s.pop(); + reverse(s); + insertAtbottom(s,t); + +} +int main(){ + stack s; + s.push(1); + s.push(2); + s.push(3); + s.push(4); + s.push(5); + s.push(6); + + reverse(s); + + while (!s.empty()) + { + cout<