home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
listings
/
v_08_09
/
8n09119b
< prev
next >
Wrap
Text File
|
1990-07-09
|
2KB
|
52 lines
class Node {
public:
Node( T x) { val = x; Next = 0; }
Node *next() { return Next; }
void link( Node *neighbor) { Next = neighbor; }
T value() { return val; }
private:
Node *Next;
T val;
};
class Stack {
public: // these members are public
Stack() { head = 0; }
// precondition: !isfull()
void push( int x)
{
Node *p = new Node( x);
if( head == 0)
head = p;
else {
p->link( head);
head = p;
}
}
// precondition: !isempty()
int pop()
{
int r = head->value();
Node *p = head;
head = head->next();
delete p;
return r;
}
Truth isempty() { return head == 0; }
Truth isfull()
{
Node *p = new Node( 0);
delete p;
return (p == 0);
}
private: // these (data) members are private
Node *head;
};