Write code to deal with cases outside the expected cases.
Basically, I dealt with two situations:
- More pops than pushes.
- More than 100 pushes.
EXCEPTION: printf("Error: Exiting.\n");
return 0;
This means that the state of the stack is tested BEFORE any changes are made. Later versions of this, instead of exiting, will modify the stack to allow for additional pushes.
Here's POP:
#define POP if (current == base) goto EXCEPTION; pop(); // deal with extra pop.
I used a compiler directive to tie the test with the pop.
Here's PUSH:
#define PUSH(x) if (current == (base+stackSize)) goto EXCEPTION; push(x);
Next: Expanding the stack.
No comments:
Post a Comment