quote:Original post by Leanna
void Stack:ush(double item_to_push)
{
data[top_of_stack] = item_to_push;
top_of_stack++;
if (top_of_stack > SIZE)
cout << "Error \n";
}
getting closer. i apologize for not reading the entire thread, but if top_of_stack is the position of the actual item that is top_of_stack then you''ll want to increment top_of_stack _before_ you push the item_to_push onto the stack. if top_of_stack points to the first "empty" position at the top of the stack, ignore this:
think of it as a simple array and numbers.
say i have this:
int myArray[10];
myArray[o] = some_item;
int top_of_stack = 0; //top_of stack now "points" to some_item
if we go through your function now:
data[top_of_stack] = item_to_push;
at this point top_of_stack == 0, so you''ve put item_to_push into the zeroth position of the array. however, some_item was there, so you''ve now over-written it.
make sense? so increment top_of_stack _before_ you put the item into the array. you''ll want to do a check against SIZE between that increment and the actual insertion of the item_to_push.
hope this is all starting to make sense.
-me