Sotirios Delimanolis
Sotirios Delimanolis

Reputation: 279940

Should a Stack have a maximum size?

I'm practicing my knowledge of ADTs by implementing some data structures, even if most already exist. With Stacks, a lot of books and other documentation I've read talk about the stack throwing an error when you try to add an element but the stack is full. In a java implementation (or any other), should I specifically keep track of a maximum stack size (from constructor), check to see if that size is reached, and throw an overflow exception if it is? Or is not such a big deal?

Upvotes: 1

Views: 186

Answers (1)

David-SkyMesh
David-SkyMesh

Reputation: 5171

Depends on the kind of stack, but usually, it doesn't matter about size if the stack is heap-allocated.

If your stack is really allocated on the stack, then you should keep it small.

Upvotes: 5

Related Questions