I'm trying to learn linked-lists in Java and had some questions about the code below:
public class List {
Node root;
public List() {
// constructor
}
public int pop() {
// pop logic
}
public int push(int data) {
// push logic
}
}
I'd like to have a List class for popping and pushing data into the linked list. However, since the list won't have any default data on instantiation, what would be the best way for storing a reference to the root node?
In C, I would just have a pointer like:
Node * root;
But since Java does not have pointer, would having a simple declaration like:
Node root;
... be acceptable? I haven't used Java in a while, but doesn't allocating memory to an object declared as a class variable cause potential memory issues? Thanks!