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

#include "mydefs2b.h"
#include <assert.h>
// Linked list implementation of stacks.

node :: node(int d, node* n) {
data = d;
next = n;
}
int Istack :: pop()
{
assert( !isempty() );
int temp = top -> data;
node* oldtop = top;
top = top -> next;
delete oldtop;
return temp;
}

void Istack :: push(int x) {
top = new node(x, top); }

// get data
// point to old // unlink old // discard

16-Mar-98

Page 16

C201/TAM/AGS