edelossantos
asked on
Reversing Queue Condensed Version() {
// Need to input multiple integers and get them returned in reversed order. This code does not print in reverse.
#include <iostream>
#include <stack>
using namespace std;
int main(void)
{
stack<int> IntStack;
int Num;
cout << "Enter an integer (or CTRL z to end data entry): ";
cin >> Num;
while(! cin.fail())
{
IntStack.push(Num);
cout << "Enter an integer (or CTRL z to end data entry): ";
cin >> Num;
}
cout << endl << "The numbers in reverse order are:" << endl;
while (! IntStack.empty())
{
Num = IntStack.top();
IntStack.pop();
cout << Num << endl;
}
return 0;
}
#include <iostream>
#include <stack>
using namespace std;
int main(void)
{
stack<int> IntStack;
int Num;
cout << "Enter an integer (or CTRL z to end data entry): ";
cin >> Num;
while(! cin.fail())
{
IntStack.push(Num);
cout << "Enter an integer (or CTRL z to end data entry): ";
cin >> Num;
}
cout << endl << "The numbers in reverse order are:" << endl;
while (! IntStack.empty())
{
Num = IntStack.top();
IntStack.pop();
cout << Num << endl;
}
return 0;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Your shell is set up to suspend the process when you press control-Z.
I found I could press almost any control character such as control-A to break out of the input loop. Try different ones, if none work for you, I would rework the input loop to look for a certain character such as a . (period) to break out of the input loop.
You could also change the suspend character of your shell, but that seems a little drastic.
I found I could press almost any control character such as control-A to break out of the input loop. Try different ones, if none work for you, I would rework the input loop to look for a certain character such as a . (period) to break out of the input loop.
You could also change the suspend character of your shell, but that seems a little drastic.
ASKER
Enter an integer (or CTRL z to end data entry): 1
Enter an integer (or CTRL z to end data entry): 2
Enter an integer (or CTRL z to end data entry): 3
Enter an integer (or CTRL z to end data entry): 4
Enter an integer (or CTRL z to end data entry): 5
Enter an integer (or CTRL z to end data entry): 6
Enter an integer (or CTRL z to end data entry): 7
Enter an integer (or CTRL z to end data entry): 8
Enter an integer (or CTRL z to end data entry):
[1]+ Stopped a.out
// why am I getting this output?