﻿1
00:00:00,440 --> 00:00:06,850
‫So now we're going to create our pre penned function and pre penned is going to look like this.

2
00:00:06,860 --> 00:00:09,020
‫We'll create a new node.

3
00:00:09,290 --> 00:00:17,990
‫We will point that new node at the first node by setting it equal to head, and they will have head

4
00:00:17,990 --> 00:00:19,340
‫point at that new node.

5
00:00:19,340 --> 00:00:22,010
‫And that adds that into the linked list.

6
00:00:22,400 --> 00:00:25,490
‫That's how it works if we have items in the linked list.

7
00:00:25,490 --> 00:00:31,760
‫But if we have an empty linked list, we'll have head and tail point to that new node.

8
00:00:32,210 --> 00:00:37,210
‫So we'll start off that function like this will pass it a value.

9
00:00:37,220 --> 00:00:42,170
‫We'll use that value to create a node like this.

10
00:00:42,560 --> 00:00:48,710
‫So the next thing we'll code for is when we have an empty linked list where we have head and tail point

11
00:00:48,710 --> 00:00:49,970
‫to that new node.

12
00:00:50,210 --> 00:00:55,400
‫But the first thing we need to do is test to see is the length list empty.

13
00:00:55,700 --> 00:00:58,900
‫So we'll say if length is equal to zero.

14
00:00:58,910 --> 00:01:06,590
‫And you could also say if head is equal to null pointer, then we'll set head to be equal to new node

15
00:01:06,590 --> 00:01:13,010
‫like this and then we'll set tail to be equal to new node like this.

16
00:01:13,340 --> 00:01:16,580
‫So let's add this in with the rest of our code.

17
00:01:16,790 --> 00:01:21,920
‫So now let's code for when we do have items in the length list, we'll say else.

18
00:01:21,920 --> 00:01:25,130
‫And now let's build out this else statement.

19
00:01:25,970 --> 00:01:29,780
‫We'll say new node next equals head.

20
00:01:30,350 --> 00:01:35,510
‫That's going to do this and point that node to the first node in the linked list.

21
00:01:36,210 --> 00:01:42,930
‫Then we'll say head equals new node and that moves head over like this and adds this into the length

22
00:01:42,930 --> 00:01:43,590
‫list.

23
00:01:44,010 --> 00:01:50,280
‫So now let's add this and with the rest of our code and the only other thing that we need to do is to

24
00:01:50,280 --> 00:01:52,620
‫increase the length by one.

25
00:01:52,920 --> 00:01:56,130
‫So we'll look at this code in a moment and vs code.

26
00:01:56,130 --> 00:02:04,140
‫And when we do we're going to create this length list with two and three and then we will pretend a

27
00:02:04,140 --> 00:02:09,150
‫node with a value of one and our linked list will be one, two, three.

28
00:02:09,540 --> 00:02:13,170
‫So now let's go take a look at this NVS code.

29
00:02:14,080 --> 00:02:21,160
‫So there is our pre pin function there and I'll scroll up so we can take a look at our main function.

30
00:02:21,550 --> 00:02:27,880
‫And this creates our linked list with two nodes with a values of two and three, and then with this

31
00:02:27,880 --> 00:02:31,030
‫line will print this out and I'll run this.

32
00:02:31,600 --> 00:02:36,520
‫And you can see up here that our linked list has values of two and three.

33
00:02:37,150 --> 00:02:39,790
‫So I'm going to come up here and add a line.

34
00:02:40,910 --> 00:02:47,960
‫And with this line we'll pretend a node with a value of one and they will print this out again and I'll

35
00:02:47,960 --> 00:02:49,430
‫run this.

36
00:02:50,060 --> 00:02:55,190
‫And now you can see our linked list has values of one, two and three.

37
00:02:56,090 --> 00:02:59,990
‫And that is our function for pretend.

