1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

A derivation of stacks using linked lists(Linkstack.h) #include <assert.h>

template<class T>
class Link_stack :public Gstack<T> {
struct node {
Tdata;
node* next;
node(
Td, node* n)
{data = d; next = n; }
};
node* top;
public:
Link_stack()
{ top = NULL; }
void push(Tx)
{ top = new node(x, top); }
Tpop(){
assert( !isempty() );
Tt = top -> data;
node* oldtop = top;
top = top -> next;
delete oldtop;
return t;
}
bool isempty()
{ return( top == NULL ); }
bool isfull()
{ return( FALSE ); }
};

22-Mar-98

Page 4

C201/TAM