#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class employee
{
int eno;
char *ename;
char *deptname;
public:
employee()
{
}
employee(int no,char name[],char dname[])
{
eno=no;
ename=name;
deptname=dname;
}
friend ostream & operator<<(ostream &tout,employee &temp);
};
ostream & operator<<(ostream &tout,employee &temp)
{
tout<<"\n details of employee number:"<<temp.eno<<endl;
tout<<"\n name is:"<<temp.ename<<endl;
tout<<"\n department name is:"<<temp.deptname;
return tout;
}
template <class eletype>
class stack
{
int sp;
eletype sa[10];
public:
stack()
{
sp=0;
}
void push(eletype);
eletype pop();
};
template <class eletype>
void stack<eletype>::push(eletype value)
{
if(sp==9)
cout<<"stack overflow can't insert";
else
{
sa[sp]=value;
sp++;
}
}
template <class eletype>
eletype stack<eletype>::pop()
{
if(sp==0)
cout<<"stack underflow can't pop";
else
{
sp--;
}
return sa[sp];
}
void main()
{
clrscr();
stack<int>mystack;
mystack.push(10);
mystack.push(20);
cout<<mystack.pop()<<endl;
cout<<mystack.pop()<<endl;
stack<char>yourstack;
yourstack.push('h');
yourstack.push('p');
cout<<yourstack.pop()<<endl;
cout<<yourstack.pop()<<endl;
stack<employee> empstack;
employee obj[2]={employee(1001,"dinu","mca"),employee(1002,"babu","mca")};
for(int i=0;i<2;i++)
empstack.push(obj[i]);
for(i=0;i<2;i++)
cout<<empstack.pop();
getch();
}
Comments
Post a Comment