implement stack in C using array

is it necessary to use structure to implement stack in C using array?
what if i just do it normally using array?
Last edited on
You can do it with an array. The only caveat is that you'll need to "resize" the array if you want to add more elements when the stack is full.
You'll need an array of structures, with a variable to track the top of the stack. When it's full, it's full. In practice, some stack's can grow, but all hit a limit somewhere.

If you need a stack that grows, then you can realloc the array for a larger one.
Of course it is not necessary to use a structure. But using a structure incapsulates control variables of the stack and the array itself in one entity.
Last edited on
Topic archived. No new replies allowed.