Program: 11
--------------------------------------------------------------------------------------------------------------------Program Name : 11.1.cpp
#include<iostream>
#include<string.h>
using namespace std;
template<class t>
class stack
{
public:
t data;
stack *prev;
};
template<class t>
class stacks
{
//int stack[size];
stack<t> *top;
public:
stacks()
{
top=NULL;
}
void push(t n)
{
stack<t> *temp;
/*if(top==(size-1))
{
cout<<"overflow element not entered\n";
return 1;
}*/
//else
//{
temp=new stack<t>;
temp->data=n;
temp->prev=top;
top=temp;
//return 0;
//}
}
t pop()
{
t a;
if(top==NULL)
{
cout<<"underflow:\n";
return -1;
}
else
{
a=top->data;
top=top->prev;
return a;
}
}
void display()
{
cout<<"The data in stack is:\n";
while(top!=NULL)
{
cout<<(char)top->data<<"\n^\n"<<endl;
top=top->prev;
}
}
int empty()
{
if(top==NULL)
return -1;
else
return 1;
}
};
----------------------------------------------Program Name : 11main.cpp
#include<iostream>
#include"11.1.cpp"
using namespace std;
int main()
{
stacks<int> s1,s2;
char ch;
int n;
cout<<"Start entering the elemnts in the stck for reversing:\n";
do
{
cin>>n;
s1.push(n);
cout<<"Want to enter more:\n";
cin>>ch;
}while(ch=='y');
while(s1.empty()!=-1)
s2.push(s1.pop());
s2.display();
}
-------------------------------------------------------------------------------------------------------------------