0
ArrayBoundedStack stack = new ArrayBoundedStack(5);
    stack.push(5);
    stack.push(5);
    stack.push(2);
    stack.push(3);

Would the order of the elements, from bottom to top, be 5,5,2,3?

1
  • By definition a stack is LIFO with the oldest entry at the bottom, so the strict answer to your detailed question is just "yes". Was there something else you were trying to ask? Commented Aug 27, 2015 at 21:09

1 Answer 1

1

A stack is a last-in-first-out structure; that means if you were to pop four times after doing this, you'd get 3, 2, 5, 5.

Whether the stack actually grows up or down I think is a problem at a lower level (like the processor maybe), so thinking about it in terms of bottom or top isn't necessarily useful. Though I guess if by "top" you mean "item that would be popped first", then you've got it pretty much right

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.