1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
#include<iostream>
using namespace std;
void pop(int[], int&);
int push(int[],int&,int);
void Display(int[],int);
//-Wunused Variable
int main(){
cout<<"\t\t\tHello World\n\n";
int info,resr,stacks[50],top=-1;
// int s=50;
char c='y';
while(c=='y'||c=='Y'){
cout<<"Please enter data: "; cin>>info;
resr=push(stacks[0],top,info);
if(resr!=-1)
{
cout<<"Result unsuccessful\n";
return 0;
}else{
cout<<"Your element has been pushed. Displaying your elements\n";
Display(stacks,top);
}
cout<<"Do you want to enter more elements? ";
cin>>c;
}
cout<<"Do you want to delete elements?";
cin>>c;
while(c=='y'||c=='Y'){
pop(stacks,top);
cout<<"Now displaying your data: ";
cout<<endl;
Display(stacks,top);
}
return 0;
}
int push(int st[],int top,int info){
if(top==49){
return -1;
}else{
top++;
st[top]=info;
return info;
}
return 0;
}
void pop(int st[],int top){
if(top==-1){
cout<<"Underflow!\n";
}else{
top--;
}
}
void Display(int st[],int top){
for(int i=top; i>-1;--i)
cout<<st[i]<<endl;
}
|