I'm learning to implement a Stack and I'm struggling to understand what .next REALLY means. I've seen it in many data structures and it's obvious what its purpose is until I actually ask myself if it is a keyword or how it functions. It looks like it is an object but it seems to be acting like a pointer (like in a LinkedList) to each of the item
objects that are created.
Please help in any way you can to shed some light on my confusion!
class Item {
intdata;
Item next;
public Item(int data) {
this.data = data;
}
}
public class Stack {
private Item top;
public void push(int data) {
if (null == top) {
top = new Item(data);
} else {
Item item = new Item(data);
item.next = top;
top = item;
}
}
}