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

#include "mydefs2.h"
#include <assert.h>

// Linked list implementation of stacks.

Istack :: node* Istack :: new_node(int d, node* n) {
node* t = new node;
assert( t );
// space found OK
t -> data = d;
t -> next = n;
return( t );
// return pointer to stack }

void Istack :: init(int Nitems = 100) {
top = 0;
// Note Nitems not used }
void Istack :: push(int x) {
top = new_node(x, top);
}
int Istack :: pop() {
assert( !isempty() );
int t = top -> data;
node* oldtop = top;
top = top -> next;
delete oldtop;
// frees item pointed to
return t;
}
bool Istack :: isempty() {
return( top == 0 );
}
bool Istack :: isfull() {
return( 0 );
// candidate inline function? }

* * *

free store available checked Nitems is completely ignored by init delete t workslike free( t )

16-Mar-98

Page 3

C201/TAM/AGS