//stack program
template<class T>
class stack
{
private:
T *s;
int top,size;
public:
stack(int k=40);
int isempty();
T topmost();
};
template<class T>
stack<T>::stack(int k)
{
top=-1;
size=k;
s=new T[size];
}
//isempty()
template<class T>
int stack<T>::isempty()
{
return(top==-1);
}
//isfully
template<class T>
T stack<T>::topmost()
{
if(isempty())
return(-1);
else
return(s[top]);
}void main()
{
int ch,k,x;
cout<<"enter size of the stack\n";
cin>>k;
stack<int> a(k);
x=a.topmost();
if( x==-1)
cout<<"stack is empty\n";
else
cout<<"top most value of the stack is="<<x<<endl;
getch();
}
template<class T>
class stack
{
private:
T *s;
int top,size;
public:
stack(int k=40);
int isempty();
T topmost();
};
template<class T>
stack<T>::stack(int k)
{
top=-1;
size=k;
s=new T[size];
}
//isempty()
template<class T>
int stack<T>::isempty()
{
return(top==-1);
}
//isfully
template<class T>
T stack<T>::topmost()
{
if(isempty())
return(-1);
else
return(s[top]);
}void main()
{
int ch,k,x;
cout<<"enter size of the stack\n";
cin>>k;
stack<int> a(k);
x=a.topmost();
if( x==-1)
cout<<"stack is empty\n";
else
cout<<"top most value of the stack is="<<x<<endl;
getch();
}
No comments:
Post a Comment