#include<iostream>
using namespace std;
#include<conio.h>
#include<process.h>
template<class T>
class Stack
{
private:
int top,maxtop;
T *stack;
public:
Stack(int maxstacksize)
{
top=-1;
maxtop=maxstacksize;
stack=new T[maxtop];
}
~Stack()
{
delete[] stack;
}
int isfull();
int isempty();
void insertion();
void deletion();
void display();
void topmost();
};
template<class T>
int Stack<T>::isempty()
{
if(top==-1)
return 1;
else
return 0;
}
template<class T>
int Stack<T>::isfull()
{
if(top==maxtop-1)
return 1;
else
return 0;
}
template<class T>
void Stack<T>::topmost()
{
if(isempty())
cout<<"\nstack is underflow.......";
else
cout<<"\n topmost element of the stack is:"<<stack[top];
}
template<class T>
void Stack<T>::display()
{
if(isempty())
cout<<"\n stack is underflow..........";
else
cout<<"\nstack elements are :";
for(int i=0;i<=top;i++)
{
cout<<"\t";
cout<<stack[i];
}
}
template<class T>
void Stack<T>::insertion()
{
T ele;
if(isfull())
cout<<"\n stack is overflow.........";
else
{
cout<<"\n enter the element u want to insert :";
cin>>ele;
stack[++top]=ele;
}
}
template<class T>
void Stack<T>::deletion()
{
if(isempty())
cout<<"\n stack is underflow..........";
else
cout<<"\n deleted element is:"<<stack[top--];
}
int main()
{
int choice;
Stack<int> s(10);
do
{
cout<<"\n1.insertion\n2.deletion\n3.topmost\n4.display\n5.exit\n";
cout<<"\n enter ur choice :";
cin>>choice;
switch(choice)
{
case 1:
s.insertion();
break;
case 2:
s.deletion();
break;
case 3:
s.topmost();
break;
case 4:
s.display();
break;
case 5:
_exit(0);
}
}while(choice<=5);
_getch();
return 0;
}
using namespace std;
#include<conio.h>
#include<process.h>
template<class T>
class Stack
{
private:
int top,maxtop;
T *stack;
public:
Stack(int maxstacksize)
{
top=-1;
maxtop=maxstacksize;
stack=new T[maxtop];
}
~Stack()
{
delete[] stack;
}
int isfull();
int isempty();
void insertion();
void deletion();
void display();
void topmost();
};
template<class T>
int Stack<T>::isempty()
{
if(top==-1)
return 1;
else
return 0;
}
template<class T>
int Stack<T>::isfull()
{
if(top==maxtop-1)
return 1;
else
return 0;
}
template<class T>
void Stack<T>::topmost()
{
if(isempty())
cout<<"\nstack is underflow.......";
else
cout<<"\n topmost element of the stack is:"<<stack[top];
}
template<class T>
void Stack<T>::display()
{
if(isempty())
cout<<"\n stack is underflow..........";
else
cout<<"\nstack elements are :";
for(int i=0;i<=top;i++)
{
cout<<"\t";
cout<<stack[i];
}
}
template<class T>
void Stack<T>::insertion()
{
T ele;
if(isfull())
cout<<"\n stack is overflow.........";
else
{
cout<<"\n enter the element u want to insert :";
cin>>ele;
stack[++top]=ele;
}
}
template<class T>
void Stack<T>::deletion()
{
if(isempty())
cout<<"\n stack is underflow..........";
else
cout<<"\n deleted element is:"<<stack[top--];
}
int main()
{
int choice;
Stack<int> s(10);
do
{
cout<<"\n1.insertion\n2.deletion\n3.topmost\n4.display\n5.exit\n";
cout<<"\n enter ur choice :";
cin>>choice;
switch(choice)
{
case 1:
s.insertion();
break;
case 2:
s.deletion();
break;
case 3:
s.topmost();
break;
case 4:
s.display();
break;
case 5:
_exit(0);
}
}while(choice<=5);
_getch();
return 0;
}
No comments:
Post a Comment