I am reading the source code of Java LinkedList, and note that the constructor of LinkedList is like this:
public LinkedList() {
header.next = header.previous = header;
}
How much space will be allocated to this initialization, the header seems to create infinite recursion by pointing to itself.
It allocates a single node in the initialization of the
headerinstance variable:The code in the constructor to which you refer allocates no memory; it merely sets up the pointers to an initial state. There is no “infinite recursion”, because internal traversal caters for this situation.