-
c stack
Could someone help me write a short program to determine the value at the bottom entry in a stack w/o changing the stack?
Thanks, I'm a bit over my head in an algorithms course.
This stack has a seperate interface and an implementation file with the code for the push, pop, init, and empty functions.
Heres what I have as an idea?
int STACKvalue (int value)
int i, N = 0;
Item x[value];
while (!STACKempty)
{
x[N] = STACKpop();
N++;
}
-
hmm..
And what kind of stack do you refer to?
i mean .. is this the stack that the exe file is allocating ?
or it is some data structure you made in some program?
if it is the second, post your stack data structure implementation here, so anyone could know what you're talking about...
-
First of all, which implementation of a stack are you using? If it's an array implementation, then just reference the index where your first item is.
If it's not an array (i.e. linked list or something), use what Salem suggested and just keep popping from the current stack and placing the results on another stack. Then the top value on the new stack is the bottom value from the stack that you want.