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

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

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

int

node*

IMAGE imgs/lec-2002.gif

top

Linked Stack showing effect of push() and pop() operations

16-Mar-98

Page 5

C201/TAM/AGS