﻿1
00:00:00,420 --> 00:00:06,210
‫So now we're going to create our get function and get it's going to start out like this.

2
00:00:06,210 --> 00:00:11,730
‫We're going to return the pointer to the node at a particular index.

3
00:00:12,240 --> 00:00:18,330
‫So I'm going to bring up a linked list here, and I've included the indexes below each node.

4
00:00:18,570 --> 00:00:26,040
‫And when we run the git function, we can get a node at the index of zero in this case, or one or two

5
00:00:26,040 --> 00:00:27,120
‫or three.

6
00:00:27,330 --> 00:00:35,460
‫But we cannot get a node at the index of negative one, or we could say an index less than zero.

7
00:00:35,760 --> 00:00:43,500
‫And we also can't get a node at the index of four, or we could say greater than or equal to the length.

8
00:00:44,040 --> 00:00:52,230
‫So we'll start out by saying if index is less than zero or index is greater than or equal to the length,

9
00:00:52,800 --> 00:00:55,140
‫we're going to return null pointer.

10
00:00:55,530 --> 00:00:58,470
‫So let's bring our linked list back up like this.

11
00:00:58,470 --> 00:01:02,520
‫We're going to create a variable called temp that we set equal to head.

12
00:01:02,790 --> 00:01:09,870
‫We'll create that like this temp equals head and I'm going to remove head and tail from the diagram

13
00:01:10,470 --> 00:01:18,180
‫and we'll move temp through the length list by creating this for loop and saying temp equals temp next.

14
00:01:18,540 --> 00:01:26,730
‫So for example, if we wanted to get the node at the index of two, this would loop one two times and

15
00:01:26,730 --> 00:01:31,800
‫then we would say return temp, which returns that pointer to that node.

16
00:01:32,250 --> 00:01:34,980
‫So now let's put this in with the rest of our code.

17
00:01:35,340 --> 00:01:37,920
‫That is all of the code for the git function.

18
00:01:38,400 --> 00:01:40,110
‫This is all pretty straightforward.

19
00:01:40,110 --> 00:01:46,380
‫The only thing that might be a little bit difficult in this function is remembering to do this if statement

20
00:01:46,380 --> 00:01:50,280
‫to test, to make sure that your index is valid.

21
00:01:50,640 --> 00:01:53,610
‫So we'll look at this code and a moment in VZ code.

22
00:01:53,610 --> 00:02:00,570
‫And when we do, we'll create a linked list that looks like this where the value of each node is the

23
00:02:00,570 --> 00:02:08,340
‫same as the index, and then we'll get the node at the index of two and that will return this node with

24
00:02:08,340 --> 00:02:09,570
‫a value of two.

25
00:02:10,050 --> 00:02:14,040
‫So now let's flip over to VS code and take a look at this.

26
00:02:14,830 --> 00:02:22,240
‫So there is our get member function there and then I'm going to scroll up and this is going to create

27
00:02:22,240 --> 00:02:29,950
‫that linked list with values zero through three and then we're going to get the node at the index of

28
00:02:29,950 --> 00:02:31,840
‫two and I'll run this.

29
00:02:32,690 --> 00:02:35,110
‫And that returns a node.

30
00:02:35,120 --> 00:02:38,540
‫So I'm going to come over here to the get and I'm going to add.

31
00:02:39,760 --> 00:02:40,750
‫Value.

32
00:02:41,440 --> 00:02:42,910
‫And then we'll run it again.

33
00:02:43,800 --> 00:02:48,450
‫And you can see that this is return the node with a value of two.

34
00:02:48,840 --> 00:02:55,080
‫So I want to point out here that get function does not remove the node.

35
00:02:55,290 --> 00:02:57,770
‫The node remains in the linked list.

36
00:02:57,780 --> 00:03:01,560
‫We're just returning a pointer to a particular node.

37
00:03:01,890 --> 00:03:04,290
‫So that is our function.

38
00:03:04,680 --> 00:03:05,820
‫Forget.

