‫So now we're going to create our delete first function.
‫I'll bring up a doubly linked list and with delete first it's just going to look like this.
‫And we have an edge case for when we have one node and another edge case for when we have an empty linked
‫list.
‫So we'll start the code out like this, and the first thing we'll do is write the code for when the
‫linked list is empty.
‫Will say if the length is equal to zero, we'll just run return.
‫So now let's write the code for when we have one item in the length list.
‫We'll start out by creating that variable temp and we'll create it like this temp equals head, and
‫then we'll say if the length is equal to one, we'll set head and tail to be equal to null pointer.
‫Like this.
‫So let's add this in with the rest of our code.
‫So this is for when the length list is empty, and this is for when we have one item and for two or
‫more items we'll say else.
‫And now let's build out this else statement.
‫We'll move head over by saying head equals head next.
‫And we'll do that with this line of code.
‫Head equals head next.
‫And that'll move that over.
‫Then we'll say head previous equals null pointer and that'll do that.
‫And we'll do that with this line of code head previous equals null pointer.
‫So let's add this in with the rest of our code and we have a couple more steps to do and we'll say delete
‫temp and that will remove that node from memory and then we'll decrement the length by one.
‫So let's add this in with the rest of our code and that is the entire delete first member function.
‫We'll look at this code in a moment and VS code.
‫And when we do, we'll create this doubly linked list and then we'll run delete first three different
‫times to make sure it works when we have two or more items and one item and then we'll run it a third
‫time to make sure it works when the linked list is empty.
‫So now let's flip over and take a look at this.
‫So there is our delete first member function.
‫They're added to our doubly linked list class, and then I'll scroll up and in our main function that
‫creates that doubly linked list with values of two and one.
‫And with this we'll print out that linked list and I'll scroll up again.
‫And with this code we'll run delete first three different times.
‫First, when we have two items and then with one item and then we'll run it a third time to make sure
‫it works when we don't have any items.
‫So I'll run this.
‫And up here we have our double length list with two items in it.
‫And then we ran delete first and removed one.
‫And then here we ran it again.
‫And the doubly linked list is empty.
‫So we run it one more time to make sure it works on an empty, doubly linked list.
‫And it looks like we have a working function for delete first.