Sunday, 25 September 2011

Checking stack is empty ( UNDERFLOW OF STACKS) or not?


UNDERFLOW OF STACKS
A stack underflow means that stack is empty and you can't delete any data from it.

#include<iostream.h>
#include<conio.h>
template<class T>
class stack
{
 private:
    T *s;
    int top,size;
 public:
    void push(T,x);
    T pop();
    stack(int k=40);
    ~stack();
    stack isfull();
    int isemptly();
    void display();
    T topmost();
 };
stack<T>::stack(int k)
{
  size=k;
  top=-1;
  s=new T[size];
}
stack<T>::~stack()
{
 }
int stack<T>::isempty()
{
  return(top==-1);
}
void main()
{
  stack<int> a;
  a.isempty();
  getch();
}

Basic stack operation

No comments:

Post a Comment