﻿1
00:00:00,420 --> 00:00:03,240
‫So now we're going to create our append function.

2
00:00:03,510 --> 00:00:07,800
‫So append with a singly linked list looked like this.

3
00:00:07,830 --> 00:00:10,260
‫We created a new node.

4
00:00:10,440 --> 00:00:17,760
‫We had the last node in the linked list point to that new node tail points to that new node and that

5
00:00:17,760 --> 00:00:25,350
‫adds that into the length list with a doubly linked list that is very similar, except we have these

6
00:00:25,350 --> 00:00:26,760
‫extra pointers.

7
00:00:26,760 --> 00:00:33,930
‫So that green pointer there will be the only difference between a singly linked list and a doubly linked

8
00:00:33,930 --> 00:00:35,970
‫list for the append function.

9
00:00:36,330 --> 00:00:42,600
‫So we're still going to point that last node to the new node, but we also need to take that previous

10
00:00:42,600 --> 00:00:50,250
‫pointer from the new node and point it at that last node and then we'll move tail over and that adds

11
00:00:50,250 --> 00:00:53,160
‫that node into our doubly linked list.

12
00:00:53,580 --> 00:00:59,640
‫And just like with a singly linked list, we'll also have to code for when we have an empty doubly linked

13
00:00:59,640 --> 00:01:00,210
‫list.

14
00:01:00,510 --> 00:01:05,550
‫And when this happens, we'll have head and tail point to that new node.

15
00:01:06,170 --> 00:01:08,650
‫So we'll start our function off like this.

16
00:01:08,660 --> 00:01:10,070
‫We pass it a value.

17
00:01:10,100 --> 00:01:12,950
‫We use that to create a new node.

18
00:01:13,900 --> 00:01:22,570
‫Like this and we'll code for when we have an empty double length list first where we have head and tail

19
00:01:22,570 --> 00:01:24,100
‫point to this new node.

20
00:01:24,370 --> 00:01:30,430
‫So in order to do this, we have to test to see is the length list in fact empty.

21
00:01:30,610 --> 00:01:34,660
‫And we'll do that by saying if length is equal to zero.

22
00:01:34,960 --> 00:01:42,010
‫And you could also do this check by saying if head is equal to null pointer and then we'll set head

23
00:01:42,010 --> 00:01:49,750
‫to be equal to new node like this and we'll set tail to be equal to new node like this.

24
00:01:50,350 --> 00:01:56,350
‫So let's add this in with the rest of our code we've coded for when we have an empty linked list now

25
00:01:56,350 --> 00:02:03,070
‫we'll code for when we have items in the length list, we'll say else and let's build out this else

26
00:02:03,160 --> 00:02:12,610
‫statement and we'll start this out by saying Tail next equals new node that is tail next equals new

27
00:02:12,610 --> 00:02:13,210
‫node.

28
00:02:13,970 --> 00:02:17,690
‫And then we'll say new node, previous equals tale.

29
00:02:17,690 --> 00:02:24,230
‫And that points that previous pointer from that new node at the same node that tail is pointing to.

30
00:02:24,560 --> 00:02:28,790
‫And then we'll set tail to be equal to new node like this.

31
00:02:28,790 --> 00:02:32,060
‫And that adds that into our doubly linked list.

32
00:02:32,690 --> 00:02:39,680
‫So let's add this in with the rest of our code, and the only thing left to do is to increase the length

33
00:02:39,680 --> 00:02:40,820
‫by one.

34
00:02:41,240 --> 00:02:43,220
‫So that is our append function.

35
00:02:43,220 --> 00:02:46,040
‫We'll look at this code in a moment in VZ code.

36
00:02:46,040 --> 00:02:52,310
‫And when we do, we'll start out with a linked list that looks like this and then we'll run, append

37
00:02:52,310 --> 00:02:56,870
‫and add a second item and our linked list will look like this.

38
00:02:57,170 --> 00:03:00,350
‫So now let's flip over and take a look at this.

39
00:03:01,050 --> 00:03:08,780
‫So there is our append member function added to our doubly linked list class and then I'll scroll up

40
00:03:08,790 --> 00:03:10,740
‫and this is our main function.

41
00:03:11,100 --> 00:03:17,940
‫This creates that doubly linked list with one node with a value of one, and with this line we'll print

42
00:03:17,940 --> 00:03:19,770
‫that out and I'll run this.

43
00:03:20,340 --> 00:03:25,620
‫And you can see up here that our linked list has one node with a value of one.

44
00:03:26,220 --> 00:03:29,220
‫And I'm going to come up here and add a line.

45
00:03:30,060 --> 00:03:34,170
‫And this will opin that second node with a value of two.

46
00:03:34,650 --> 00:03:36,330
‫And now I'll run this.

47
00:03:37,050 --> 00:03:44,250
‫And now we have a doubly linked list with two nodes with a value of one and two.

48
00:03:44,760 --> 00:03:48,450
‫And that is our function for append.

