This is specifically a doubly linked list. Each node has a pointer to the next one, and a pointer to the last one. The constructor will do the following, in more C-style syntax:
1 2 3 4 5 6 7 8 9
Node Node(inValue,inNext,inPrev){
Node Node;
Node.mValue=inValue;//point to the data
Node.mNext=inNext;//point to the next node
Node.mPrev=inPrev;//point to the previous node
if(Node.mPrev)Node.mPrev->mNext=&Node;//make the previous node point to us as its next node
if(Node.mNext)Node.mNext->mPrev=&Node;//make the next node point to us as its previous node
return Node;//now give whoever called us the new node.
}
That's basically what it does. Make sure you learn the weird f(param): var(param) syntax, it's called an initializer list. Some people use it a lot to save typing a lot of constructor calls in a constructor.
The destructor does this:
1 2 3 4 5 6
void ~Node(Node){
if(Node.mPrev)Node.mPrev->mNext = Node.mNext;//make the previous node point to the next node instead of us.
if(Node.mNext)Node.mNext->mPrev = Node.mPrev;//make the next node point to the previous one.
Node.mNext=Node.mPrev=0;//the node should no longer point to either the next or previous ones.
//now the node will be deallocated, and we can rest assured that no-one has a pointer to it. (or can we?)
}
That's basically what it does. Make sure you learn the weird f(param): var(param) syntax, it's called an initializer list. Some people use it a lot to save typing a lot of constructor calls in a constructor.
Actually it goes beyond save typing of code. If you read Scott Meyers Effective C++, the difference lies in how the C++ run-time initialize those members. They are not the same from that point of view. From source code point of view, you feel it is saving keystrokes which I used to think like that too in the past.