/*C++ program to illustrate the use of class templates*/
-----------------------------------------------------------------------------
#include
#include
const int MAX=10;
template
class stack
{
T stk[MAX];
int top;
public:
stack()
{
top=-1;
}
void push(T data)
{
if(top==MAX-1)
cout<
{
top++;
stk[top]=data;
}
}
T pop()
{
if(top==-1)
{
cout<
}
else
{
T data=stk[top];
top--;
return data;
}
}
};
void main()
{
clrscr();
stack
s1.push(10);
s1.push(20);
s1.push(30);
cout<
s2.push(3.14);
s2.push(6.28);
s2.push(8.98);
cout<
}
OUTPUT:
10
20
30
3.14
6.28
8.98D
No comments:
Post a Comment
Your comment may wait for moderation....