‫So now we're going to create our append function.
‫So append with a singly linked list looked like this.
‫We created a new node.
‫We had the last node in the linked list point to that new node tail points to that new node and that
‫adds that into the length list with a doubly linked list that is very similar, except we have these
‫extra pointers.
‫So that green pointer there will be the only difference between a singly linked list and a doubly linked
‫list for the append function.
‫So we're still going to point that last node to the new node, but we also need to take that previous
‫pointer from the new node and point it at that last node and then we'll move tail over and that adds
‫that node into our doubly linked list.
‫And just like with a singly linked list, we'll also have to code for when we have an empty doubly linked
‫list.
‫And when this happens, we'll have head and tail point to that new node.
‫So we'll start our function off like this.
‫We pass it a value.
‫We use that to create a new node.
‫Like this and we'll code for when we have an empty double length list first where we have head and tail
‫point to this new node.
‫So in order to do this, we have to test to see is the length list in fact empty.
‫And we'll do that by saying if length is equal to zero.
‫And you could also do this check by saying if head is equal to null pointer and then we'll set head
‫to be equal to new node like this and we'll set tail to be equal to new node like this.
‫So let's add this in with the rest of our code we've coded for when we have an empty linked list now
‫we'll code for when we have items in the length list, we'll say else and let's build out this else
‫statement and we'll start this out by saying Tail next equals new node that is tail next equals new
‫node.
‫And then we'll say new node, previous equals tale.
‫And that points that previous pointer from that new node at the same node that tail is pointing to.
‫And then we'll set tail to be equal to new node like this.
‫And that adds that into our doubly linked list.
‫So let's add this in with the rest of our code, and the only thing left to do is to increase the length
‫by one.
‫So that is our append function.
‫We'll look at this code in a moment in VZ code.
‫And when we do, we'll start out with a linked list that looks like this and then we'll run, append
‫and add a second item and our linked list will look like this.
‫So now let's flip over and take a look at this.
‫So there is our append member function added to our doubly linked list class and then I'll scroll up
‫and this is our main function.
‫This creates that doubly linked list with one node with a value of one, and with this line we'll print
‫that out and I'll run this.
‫And you can see up here that our linked list has one node with a value of one.
‫And I'm going to come up here and add a line.
‫And this will opin that second node with a value of two.
‫And now I'll run this.
‫And now we have a doubly linked list with two nodes with a value of one and two.
‫And that is our function for append.