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 - Posted by | Data Structure

Chưa có phản hồi.

Gửi phản hồi

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Thay đổi )

Twitter picture

You are commenting using your Twitter account. Log Out / Thay đổi )

Facebook photo

You are commenting using your Facebook account. Log Out / Thay đổi )

Connecting to %s

Follow

Get every new post delivered to your Inbox.