Posts which you will also like.

Monday, November 23, 2009

Program to illustrate the use of class templates

-----------------------------------------------------------------------------
/*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< else
{
top++;
stk[top]=data;
}
}
T pop()
{
if(top==-1)
{
cout< return NULL;
}
else
{
T data=stk[top];
top--;
return data;
}
}
};
void main()
{
clrscr();
stacks1;
s1.push(10);
s1.push(20);
s1.push(30);
cout<stacks2;
s2.push(3.14);
s2.push(6.28);
s2.push(8.98);
cout<getch();
}

OUTPUT:
10
20
30
3.14
6.28
8.98D

No comments:

Post a Comment

Your comment may wait for moderation....

DMCA.com Protected by Copyscape Online Plagiarism Tool