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 ); }
};
|