﻿1
00:00:00,430 --> 00:00:04,190
‫So now we're going to create our delete first function.

2
00:00:04,210 --> 00:00:10,780
‫I'll bring up a doubly linked list and with delete first it's just going to look like this.

3
00:00:10,960 --> 00:00:18,040
‫And we have an edge case for when we have one node and another edge case for when we have an empty linked

4
00:00:18,040 --> 00:00:18,820
‫list.

5
00:00:19,240 --> 00:00:24,700
‫So we'll start the code out like this, and the first thing we'll do is write the code for when the

6
00:00:24,700 --> 00:00:26,110
‫linked list is empty.

7
00:00:26,110 --> 00:00:30,910
‫Will say if the length is equal to zero, we'll just run return.

8
00:00:31,450 --> 00:00:36,370
‫So now let's write the code for when we have one item in the length list.

9
00:00:36,550 --> 00:00:43,960
‫We'll start out by creating that variable temp and we'll create it like this temp equals head, and

10
00:00:43,960 --> 00:00:50,320
‫then we'll say if the length is equal to one, we'll set head and tail to be equal to null pointer.

11
00:00:50,770 --> 00:00:51,850
‫Like this.

12
00:00:52,420 --> 00:00:55,090
‫So let's add this in with the rest of our code.

13
00:00:55,450 --> 00:01:02,560
‫So this is for when the length list is empty, and this is for when we have one item and for two or

14
00:01:02,560 --> 00:01:04,840
‫more items we'll say else.

15
00:01:04,840 --> 00:01:08,470
‫And now let's build out this else statement.

16
00:01:08,710 --> 00:01:13,930
‫We'll move head over by saying head equals head next.

17
00:01:14,080 --> 00:01:16,400
‫And we'll do that with this line of code.

18
00:01:16,420 --> 00:01:18,070
‫Head equals head next.

19
00:01:18,070 --> 00:01:20,020
‫And that'll move that over.

20
00:01:20,110 --> 00:01:27,060
‫Then we'll say head previous equals null pointer and that'll do that.

21
00:01:27,070 --> 00:01:32,350
‫And we'll do that with this line of code head previous equals null pointer.

22
00:01:32,710 --> 00:01:40,480
‫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

23
00:01:40,480 --> 00:01:47,800
‫temp and that will remove that node from memory and then we'll decrement the length by one.

24
00:01:48,250 --> 00:01:54,310
‫So let's add this in with the rest of our code and that is the entire delete first member function.

25
00:01:54,460 --> 00:01:57,340
‫We'll look at this code in a moment and VS code.

26
00:01:57,340 --> 00:02:04,420
‫And when we do, we'll create this doubly linked list and then we'll run delete first three different

27
00:02:04,420 --> 00:02:11,230
‫times to make sure it works when we have two or more items and one item and then we'll run it a third

28
00:02:11,230 --> 00:02:14,800
‫time to make sure it works when the linked list is empty.

29
00:02:15,070 --> 00:02:18,160
‫So now let's flip over and take a look at this.

30
00:02:18,730 --> 00:02:21,550
‫So there is our delete first member function.

31
00:02:21,550 --> 00:02:29,920
‫They're added to our doubly linked list class, and then I'll scroll up and in our main function that

32
00:02:29,920 --> 00:02:34,690
‫creates that doubly linked list with values of two and one.

33
00:02:34,690 --> 00:02:40,030
‫And with this we'll print out that linked list and I'll scroll up again.

34
00:02:40,360 --> 00:02:44,530
‫And with this code we'll run delete first three different times.

35
00:02:44,800 --> 00:02:51,130
‫First, when we have two items and then with one item and then we'll run it a third time to make sure

36
00:02:51,130 --> 00:02:53,980
‫it works when we don't have any items.

37
00:02:54,280 --> 00:02:55,690
‫So I'll run this.

38
00:02:56,380 --> 00:03:00,070
‫And up here we have our double length list with two items in it.

39
00:03:00,070 --> 00:03:03,040
‫And then we ran delete first and removed one.

40
00:03:03,040 --> 00:03:04,780
‫And then here we ran it again.

41
00:03:04,780 --> 00:03:06,730
‫And the doubly linked list is empty.

42
00:03:06,730 --> 00:03:12,430
‫So we run it one more time to make sure it works on an empty, doubly linked list.

43
00:03:13,100 --> 00:03:18,020
‫And it looks like we have a working function for delete first.

