#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?
}
|