Hello Seem to be a hardest word

Just another WordPress.com weblog

Stack

class Stack
{
private:
int top,size;
EType *data;
public:
Stack(int size);
~Stack();
void push(EType &x);
void pop(EType &x);
int full();
int empty();
};

Stack::Stack(int size)
{
this->size = size;
top=-1;
data = new EType[size];
}

Stack::~Stack(){delete []data;}

int Stack::empty(){return (top==-1);}

int Stack::full(){return (top==size-1);}

void Stack::push(EType &x)
{
if(full())
{
cout<<endl<<”stack over flow”;
return;
}
data[++top] = x;
}

void Stack::pop(EType &x)
{
if(empty())
{
cout<<endl<<”stack is empty”;
return;
}
x = data[top--];
}

Tháng Sáu 22, 2008 Đăng bởi fate | Data Structure | | No Comments Yet