Click here to hide categories Click here to show left categories

User: Home          welcome : Guest          Log In / Register here     




Template Example

RETURNING MORE THAN ONE VALUE

								
#include
#include

template

class datastack
{
T stack[45];
int top;
public:
datastack()
{
top=0;
}

void push(T element)
{
top++;
stack[top]=element;
}

T pop(void)
{
int q=stack[top];
top--;
return q;
}

int getsize(void)
{
return top;
}

void display()
{
int q;
for(q=top;q>0;q--)
cout< }
};

void main()
{
int i,j;
char a;
cout<<"Press 'c' to create char stack or 'i' to create integer stack"< cin>> a ;
if(a=='i')
{
int element;
datastack stack_int;
do
{
cout<<"1.push\t2.pop\t3.display\t4.getsize\t5.exit"< cin>>j;
switch (j)
{
case 1:
cout<<"Enter the element to push"< cin>>element;
stack_int.push(element);
break;

case 2:
stack_int.pop();
break;

case 3:
stack_int.display();
break;

case 4:
cout< break;

case 5:
i=0;
break;

default:
cout<<"Enter the correct choice" < break;

}
}while(i!=0);
}
else
{
char element;
datastack stack_char;
do
{
cout<<"1.push\t2.pop\t3.display\t4.getsize\t5.exit"< cin>>j;
switch (j)
{
case 1:
cout<<"Enter the element to push"< cin>>element;
stack_char.push(element);
break;

case 2:
stack_char.pop();
break;

case 3:
stack_char.display();
break;

case 4:
cout< break;

case 5:
i=0;
break;

default:
cout<<"Enter the correct choice"< break;

}
}while(i!=0);
}
}


Share this article   |    Print    |    Article read by 3510 times
Author:
Rohit kakria
I am software developer
Related Articles: No related article
Related Interview Questions: No related interview question