class stack { public: int info; next * stack; }To make best use of the capability of C++, one should include member functions as part of the class stack as in the array implementation. (This is the approach should in Math 10 notes M3.)
void push(int x, stack* & s) { stack p; p = new stack; p->info = x; p->next = s; s = p; }
int pop(stack* & s) { stack p; int temp; if (s == NULL){ cout << "stack underflow error\n"); exit(1);} else { temp = s->info; p = s; s = s->next; delete p; } return temp; }
This page is maintained by Dennis C. Smolarski, S.J.
© Copyright 1998, 1999 Dennis C. Smolarski, SJ, All rights reserved.
Last changed: 7 April 1999.