Skip to content

Instantly share code, notes, and snippets.

@Onaiplee
Created June 27, 2014 23:24
Show Gist options
  • Save Onaiplee/010808c9ac82c8fa4c04 to your computer and use it in GitHub Desktop.
Save Onaiplee/010808c9ac82c8fa4c04 to your computer and use it in GitHub Desktop.
void reverse(stack<int> &st) {
if (!st.empty()) {
int temp = st.top();
st.pop();
reverse(st);
insert_botom(st, temp);
}
}
void insert_botom(stack<int> &st, int val) {
if (st.empty()) {
st.push(val);
} else {
int temp = st.top();
st.pop();
insert_botom(st, val);
st.push(temp);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment