are they dynamic or static?
When I'm talking about stacks in C programming...?
They can be either. You could look at all stacks as dynamic by definition, since you an push or pop them as needed, but they are actually static if you initialize the stack at a given size and never push or pop anything off it.
http://en.wikipedia.org/wiki/Stack_%28da...
Reply:could be either, depending on how the stack is implemented. I am not a comp sci guy so don't ask me if those guys have some other wierd defintion for the terms "static" and "dynamic". There is no builtin "stack" in C so you have to create it yourself (or use a stack that some other programmer like yourself created)
a stack is just a data structure where the last item put on top of the stack ("pushed") is the first item out ("popped") ... a classical FIFO
when you implement this, you can either:
(1)allocate a fixed amount of memory which means regardless of how many items are on the stack, the stack will occupy the same amount of memory and there will be an upper limit to the the number of items that can be on the stack at any one time
- OR -
(2) allocate memory as items are pushed or free memory as items are popped from the stack, in this case the only limit to the number of items on the stack at any one time is the amount of available memory.
I would call implementation (1) "static" and implementation (2) "dynamic" ... I beleive both are valid examples of the stack data structure.
**************************************...
as far as the true/false question goes, I would guess if you had to pick one, I would say "true", because most stacks are probably programmed following implementation (1)
Reply:Here's a clue: One common problem while developing a recursive algorithm is stack overflow, where the program just runs out of stack space because the recursive function doesn't have a good termination condition. Think about that and see if it helps you answer the question.
Hope that nudges you to the right answer.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment