#include <iostream>
using namespace std;
template<class Type>
class stack
{
Type s[10];
int top=-1,size;
public:
stack()
{
cout<<"\nenter the size of stack::";
cin>>size;
}
void push(Type item)
{
if(top==size-1)
cout<<"\nstack is full!!";
else
{
top++;
s[top]=item;
}
}
void pop()
{
if(top==-1)
cout<<"\nstack is empty!!";
else
{
cout<<"\npopped element:"<<s[top];
top--;
}
}
void stack_op();
};
template<class Type>void stack<Type>::stack_op()
{
Type item;
int choice=1,i;
while(choice>0&&choice<3)
{
cout<<"\n1..push\t2..pop\t3.display\tenter eny key to exist!!";
cout<<"\n enter the choice::";
cin>>choice;
switch(choice)
{
case 1: cout<<"enter the item::";
cin>>item;
push(item);
break;
case 2: pop();
break;
case 3: cout<<"\n items in the stack are::";
for(i=0;i<=top;i++)
{
cout<<s[i]<<"\t";
}
break;
default:cout<<"invalid choice!!";
}
}
};
int main()
{
cout<<"\nstack operation using templates";
cout<<"\nint stack!!";
stack<int>s1;
cout<<"\n float stack!!";
stack<float>s2;
int choice;
while(1)
{
cout<<"\n1..INT\t2..FLOAT\tenter any key to exit!!";
cout<<"\nenter the choice::";
cin>>choice;
switch(choice)
{
case 1:s1.stack_op();
break;
case 2:s2.stack_op();
break;
default:exit(0);
}
}
return 0;
}