I am studying the java stack, and am just curious about the pointer in this particular scenario.
When we push an object or a node onto our stack, where does this point:
- at the front of the first node?
- at the back of the first node?
Can anybody help me on this or give some demo link describing a stack pushing and popping the node in the stack? And give me details on where the pointer is pointing any given time.
This is how a stack works:
You push elements into it like this. The freshly added elements are always “on top” since it is a Last in First Out (LIFO) structure. You can only access the top element:
Then You can pop these elements, but pop always removes the top one, like this:
If i misunderstood your question, please write a comment, and I will delete this post!