#include "gen_stack.h" #include #define MAXSIZE 10 gstack::gstack(int capacity) { values = new void*[capacity]; this->capacity = capacity; top = -1; } gstack::gstack(const gstack &old_gstack) { int i; values = old_gstack.values; capacity = old_gstack.capacity; top = old_gstack.top; for (i = 0; i < capacity; i++) values[i] = old_gstack.values[i]; } gstack::~gstack() { delete values; } void *gstack::vpush(void *value) { return values[++top] = value; } void *gstack::vpop() { return values[top--]; } bool gstack::empty() { return top < 0; } bool gstack::full() { return top >= capacity - 1; } /* int main() { int i, j[MAXSIZE], k[MAXSIZE]; gstack s1(MAXSIZE), s2(MAXSIZE); for (i = 0; i < MAXSIZE; i++) { j[i] = i; k[i] = i*i; } for (i = 0; !s1.full() && !s2.full(); i++) { s1.vpush((void *)&j[i]); } for (i = 0; !s1.empty(); i++) { printf("%d\n", *((int *)s1.vpop())); } return 0; } */