#include<iostream>
#include<stdlib.h>
#include<stack>
using namespace std;
#define Stacksize 10
int main()
{
int choice;
char ans;
int a[5], x;
stack<int> Reggie;
again:
cout<<"Please Enter Desired Stack Operation: " <<endl <<endl;
cout<<"[1]Push" <<endl <<endl;
cout<<"[2]Pop" <<endl <<endl;
cout<<"[3]Empty" <<endl <<endl;
cout<<"[4]Top" <<endl <<endl;
cout<<"[5]Quit" <<endl <<endl;
cout<<"\t" <<"Enter Choice: ";
cin>>choice;
switch(choice)
{
//[1]Push
case 1:
for(x=0 ; x; x++) Reggie.push(x);
{
cout<<"Enter an Element: ";
cin>>a[x];
Reggie.push(a[x]);
system("cls");
if(a[x]>=1)
{
while (!Reggie.empty())
{
cout<<"\t" <<"The Element [" <<Reggie.top() <<"] has been pushed..." <<endl <<endl;
Reggie.pop();
}
goto again;
}
else if(a[x] == -1 || a[x] == 0)
{
cout<<"Stack Underflow!!" <<endl;
goto again;
}
else
{
return 0;
}
}
break;
//[2]Pop
case 2:
Reggie.push(x);
system("cls");
while (!Reggie.empty())
{
cout<<"The Elements " << "[" << Reggie.top() <<"]" <<" has been popped" <<endl <<endl;
Reggie.pop();
goto again;
}
break;
//[3]Empty
case 3:
//<if statements here>
break;
//[4]Top
case 4:
//<if statements here>
break;
//[5]Quit
case 5:
cout<<"\tWanna quit? <Y/N> ";
cin>>ans;
if (ans == 'Y' || ans == 'y')
{
system("cls");
cout<<"\t\t\t\tGoodbye~!!" <<endl;
}
else if (ans == 'N' || ans == 'n')
{
system("cls");
goto again;
}
break;
default:
system("cls");
}
return 0;
}
So.. my problem there is.. When I choose the Stack operation 1 (which is Push), it still shows in the output that it "Pushes" the number that I entered... Now my problem is, when I try to pop the number that I pushed... it only pops the number 0, why is that? I mean, what part of the code do I need to change?
And, how am I gonna make the number that I pushed be placed into the Memory, so that when I Pop it, it will show all of the number that I entered starting from the Last one up to the first one?
So.. thanks so much for the help in advance.
EDIT:
Oh, I haven't done the 3 and 4 Stack Operation Codes yet, because I cant get past the 1 and 2 so...
This post has been edited by RuneKnight XD: 16 September 2010 - 09:07 AM

New Topic/Question
Reply




MultiQuote






|