PDA

View Full Version : [SOLVED] C Stack



cap10Ibraim
May 8th, 2010, 04:10 PM
I have this question
Add to the "stack.c" an interface function void multipop(int k) that pops k elements from the stack, or until the stack is empty

I can solve it but I changed the prototype to include the name of the stack? How is it possible to do it and stick to this prototype given ?!

tookyourtime
May 8th, 2010, 04:22 PM
What's stack.c?

And doesn't pop normally return the value. So multi-pop should surely return multiple values? What your describing should be called something more like a delete.

Are you talking about THE stack or just any stack? If its just any stack and it's C then you will need to give it some sort of pointer to the data structure.

cap10Ibraim
May 8th, 2010, 04:31 PM
any stack and it's C then you will need to give it some sort of pointer to the data structure.
yes that's what I did but I should stick to the prototype given which is void multipop(int k)

dwhitney67
May 8th, 2010, 04:39 PM
The only way to adhere to the prototype you describe is to declare your stack object as a global variable, and frankly that would be silly. After all, this would preclude an application from supporting multiple stacks.

The approach you have taken, of passing the pointer of a stack to the function, is the best solution (for C).

cap10Ibraim
May 8th, 2010, 04:46 PM
Thanks for the support guys ):P