Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Reverse All the Elements of a Stack within That Stack... w/ only Stack Operations.
- #include <iostream>
- #include <stack>
- using namespace std;
- int main() {
- stack <int> S;
- stack <int> temp;
- stack <int> temp2;
- cout << "Enter the Stack Elements (-1 to stop): ";
- int n;
- while(true) {
- cin >> n;
- if(n < 0) break;
- S.push(n);
- }
- while(!S.empty()) {
- temp.push(S.top());
- S.pop();
- }
- while(!temp.empty()) {
- temp2.push(temp.top());
- temp.pop();
- }
- while(!temp2.empty()) {
- S.push(temp2.top());
- temp2.pop();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement