I am writing my own implementation of a doubly linked list for school assignment and I use an inner node class called Node
inside the list class, which represents list nodes that are linked to each other (as is usually the case with linked lists).
class DoublyLinkedList<T>
{
class Node
{
T obj;
}
}
I wonder, for large lists with many nodes, since each Node
object may refer to an instance of the parent list class, is it a significant overhead and suboptimal design? It surely is convenient to have as a non-static class - then the nodes may alter parent lists first
and last
references, which I have found to be great for incapsulation.
If I make Node
static, it can no longer (without explicit member reference to the list) be used to manipulate the parent lists first
and last
and I have to approach it all from the other way around - the list will assign and manipulate nodes through its own methods, that is link them to each other, unlink and naturally adjust its first
and last
values.
For the sake of good design and learning, I would like to know what is The Smart Thing To Do (c) (if any)?