﻿1
00:00:00,450 --> 00:00:03,660
‫So now we're going to create our pretend function.

2
00:00:04,110 --> 00:00:11,250
‫So with pretend we're going to create a new node and then we'll have the next pointer from the new node

3
00:00:11,250 --> 00:00:18,330
‫be set equal to head, and then we'll have the previous pointer from the first node and the linked list

4
00:00:18,330 --> 00:00:20,430
‫point back to the new node.

5
00:00:20,850 --> 00:00:25,950
‫We move head over to the new node and that adds that into our linked list.

6
00:00:26,250 --> 00:00:30,510
‫That's if we're adding this into a linked list that already has items.

7
00:00:30,960 --> 00:00:36,540
‫But if we have an empty length list, we'll have head and tail point to that new node.

8
00:00:36,780 --> 00:00:39,320
‫So we'll start our function out like this.

9
00:00:39,330 --> 00:00:41,010
‫We'll pass it a value.

10
00:00:41,040 --> 00:00:46,020
‫We'll use that value to create a node like this.

11
00:00:46,470 --> 00:00:50,730
‫And the first situation will code for is if we have an empty linked list.

12
00:00:51,410 --> 00:00:54,530
‫So we'll say if the length is equal to zero.

13
00:00:55,210 --> 00:01:01,030
‫We'll have head and tail be set equal to the new node, which does this.

14
00:01:01,480 --> 00:01:07,870
‫So now let's code for when we do have items in the length list, we'll say else and we'll build out

15
00:01:07,870 --> 00:01:09,370
‫this statement.

16
00:01:09,730 --> 00:01:16,090
‫So the first thing we'll do is have the next pointer from the new node point to the same node that head

17
00:01:16,090 --> 00:01:17,110
‫is pointing to.

18
00:01:17,110 --> 00:01:18,550
‫And that does that.

19
00:01:18,550 --> 00:01:20,530
‫We'll do that with this line of code.

20
00:01:20,560 --> 00:01:23,170
‫New node next equals head.

21
00:01:23,530 --> 00:01:29,110
‫So then we want the previous pointer from the L1 node to point to the new node.

22
00:01:29,440 --> 00:01:34,660
‫So we'll say head previous equals new node.

23
00:01:35,020 --> 00:01:37,060
‫Do that with this line of code head.

24
00:01:37,060 --> 00:01:38,890
‫Previous equals new node.

25
00:01:39,010 --> 00:01:41,650
‫Then we'll move head to point to the new node.

26
00:01:42,100 --> 00:01:48,250
‫We'll do that with this line of code head equals new node, and that adds that into our linked list.

27
00:01:48,580 --> 00:01:54,880
‫So let's add this in with the rest of our code, and the only thing left to do is to increase the length

28
00:01:54,880 --> 00:01:55,990
‫by one.

29
00:01:56,380 --> 00:01:59,590
‫So we'll look at this code in a moment in VZ code.

30
00:01:59,590 --> 00:02:06,850
‫And when we do, we're going to create a length list with two nodes with values of two and three, and

31
00:02:06,850 --> 00:02:12,700
‫then we'll pretend a node with a value of one, and then we'll have one, two, three.

32
00:02:13,000 --> 00:02:15,970
‫So now let's flip over and take a look at this.

33
00:02:16,670 --> 00:02:21,500
‫So there is our pre penned member function there and I'm going to scroll up.

34
00:02:22,190 --> 00:02:29,090
‫And in our main function, this creates our doubly linked list with two items with values of two and

35
00:02:29,090 --> 00:02:29,980
‫three.

36
00:02:29,990 --> 00:02:34,160
‫And this line here will print those out and I'll run this.

37
00:02:34,700 --> 00:02:39,560
‫And you can see that we have two nodes with a values of two and three.

38
00:02:40,070 --> 00:02:43,340
‫So now I'm going to come up here and add a line.

39
00:02:44,520 --> 00:02:48,240
‫And this will depend a node with a value of one.

40
00:02:48,240 --> 00:02:52,500
‫And then once again, this line will print that out and I'll run this.

41
00:02:53,170 --> 00:03:00,970
‫And now you can see that we have nodes with a values of one, two and three and that is our function

42
00:03:01,210 --> 00:03:02,620
‫for pre pinned.

