Hi All, am trying to find da solution for this question but am kinda confuse when they say we must use two additional stacks to reverse the order elements:
below is my coding:
#include <iostream>
#include <stack>
using namespace std;
int main() {
stack<int> allint;
int num ;
num = 0;
cout<<"Enter number "<<endl;
while (num != -99)
{ cin>>num;
allint.push(num);
}
Your coding is fine, the only problem is that you lose the original order. Should you require the original order of the stack again, you could reverse the reversed stack. Yet its more efficient just to access a copy of the original stack, than to call the function again to reverse the order. Hope that helps.