‫So now we're going to create our pretend function.
‫So with pretend we're going to create a new node and then we'll have the next pointer from the new node
‫be set equal to head, and then we'll have the previous pointer from the first node and the linked list
‫point back to the new node.
‫We move head over to the new node and that adds that into our linked list.
‫That's if we're adding this into a linked list that already has items.
‫But if we have an empty length list, we'll have head and tail point to that new node.
‫So we'll start our function out like this.
‫We'll pass it a value.
‫We'll use that value to create a node like this.
‫And the first situation will code for is if we have an empty linked list.
‫So we'll say if the length is equal to zero.
‫We'll have head and tail be set equal to the new node, which does this.
‫So now let's code for when we do have items in the length list, we'll say else and we'll build out
‫this statement.
‫So the first thing we'll do is have the next pointer from the new node point to the same node that head
‫is pointing to.
‫And that does that.
‫We'll do that with this line of code.
‫New node next equals head.
‫So then we want the previous pointer from the L1 node to point to the new node.
‫So we'll say head previous equals new node.
‫Do that with this line of code head.
‫Previous equals new node.
‫Then we'll move head to point to the new node.
‫We'll do that with this line of code head equals new node, and that adds that into our 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 we'll look at this code in a moment in VZ code.
‫And when we do, we're going to create a length list with two nodes with values of two and three, and
‫then we'll pretend a node with a value of one, and then we'll have one, two, three.
‫So now let's flip over and take a look at this.
‫So there is our pre penned member function there and I'm going to scroll up.
‫And in our main function, this creates our doubly linked list with two items with values of two and
‫three.
‫And this line here will print those out and I'll run this.
‫And you can see that we have two nodes with a values of two and three.
‫So now I'm going to come up here and add a line.
‫And this will depend a node with a value of one.
‫And then once again, this line will print that out and I'll run this.
‫And now you can see that we have nodes with a values of one, two and three and that is our function
‫for pre pinned.