This is a program..to implement stack operations..it is working fine..but
a warning message is being displayed..as " Functions containing for are not
expanded inline". I would be glad if anyone can tell me the reason for this.
Thanks for all the support.
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#define max 5
class stack
{
protected:
int st[max];
int top;
public:
stack()
{
top = -1;
}
void push()
{
int item;
cout<<"Enter the item to push :";
cin>>item;
top++;
st[top] = item;
}
int pop()
{
int item;
item = st[top];
top--;
return(item);
}
void display()
{
cout<<"\n The stack contains \n "<<endl;
for(int i = top;i>=0;i--) // here
cout<<st[i]<<endl;
}
};
class stack_cond : public stack
{
public:
void push()
{
if(top == max-1)
cout<<"\n Stack Overflow "<<endl;
else
{
stack :: push();
if(top==max-1)
cout<<endl<<"After push stack is full "<<endl;
}
}
int pop()
{
int item;
if(top == -1)
{
cout<<endl<<"Stack underflow"<<endl;
return NULL;
}
else
{
item = stack :: pop();
if(top == -1)
cout<<endl<<"After pop stack is empty"<<endl;
return(item);
}
}
void display()
{
if(top == -1)
cout<<"Stack is empty "<<endl;
else
stack :: display();
}
};
void main()
{
stack_cond s;
int choice;
cout<<"Program For Stack Using Inheritance \n";
do
{
clrscr();
cout<<"1. Push \n";
cout<<"2. Pop \n";
cout<<"3. Display \n";
cout<<"4. Exit \n";
cout<<"Enter your choice:";
cin>>choice;
switch(choice)
{
case 1: s.push();
s.display();
break;
case 2: //s.display();
choice = s.pop();
if(choice!=0)
cout<<endl<<"The item "<<choice
<<" is poped from the top of the stack"<<endl;
break;
case 3: s.display();
break;
case 4: exit(0);
}
cout<<"Press any key to continue.."<<endl;
getch();
}
while(choice!=4);
}