﻿1
00:00:00,430 --> 00:00:03,250
‫So now we're going to create our set function.

2
00:00:03,250 --> 00:00:04,480
‫And we're set.

3
00:00:04,510 --> 00:00:08,890
‫We're going to change the value of a node that's at a particular index.

4
00:00:09,310 --> 00:00:11,290
‫We're going to return a boolean.

5
00:00:11,320 --> 00:00:16,040
‫It's going to be true if we were able to set that value and false.

6
00:00:16,060 --> 00:00:18,250
‫If we were not able to set that value.

7
00:00:18,700 --> 00:00:21,130
‫So I'm going to bring up a linked list like this.

8
00:00:21,130 --> 00:00:28,390
‫And this function is similar to get in that we are looking for a node at a particular index.

9
00:00:28,780 --> 00:00:35,350
‫So we're going to have a variable temp and let's say we're going to just move this to the index of one.

10
00:00:35,830 --> 00:00:37,870
‫We will move that to here.

11
00:00:38,170 --> 00:00:42,160
‫And let's say that we're going to change that value to a four.

12
00:00:42,640 --> 00:00:46,390
‫So for now, I'm going to change this back to a three.

13
00:00:47,020 --> 00:00:50,860
‫So we're going to start out by creating this temp variable like this.

14
00:00:51,100 --> 00:00:57,310
‫And like I mentioned, there are some similarities between this and the get function.

15
00:00:57,310 --> 00:01:04,810
‫So for example, we can't set a value for a node at the index of four and we can't set a value at the

16
00:01:04,810 --> 00:01:07,000
‫index of negative one.

17
00:01:07,450 --> 00:01:11,200
‫So we've written all of the logic for this in the get function.

18
00:01:11,200 --> 00:01:19,360
‫So we can just say that temp is equal to get and that we pass the get function the index.

19
00:01:19,630 --> 00:01:22,360
‫So get is going to do one of two things.

20
00:01:22,360 --> 00:01:29,740
‫It's either going to return null pointer if it's out of range or it's going to return a pointer to a

21
00:01:29,740 --> 00:01:30,400
‫node.

22
00:01:30,790 --> 00:01:36,610
‫So we need to test this, see as this pointing to a node or is this pointing to null pointer?

23
00:01:36,700 --> 00:01:38,470
‫So we'll say if temp.

24
00:01:38,860 --> 00:01:46,450
‫In other words, if temp is pointing to a node, then we'll say temp value equals the value that we

25
00:01:46,450 --> 00:01:48,220
‫pass the set function.

26
00:01:48,520 --> 00:01:56,260
‫And if our value is four, that's going to change this to a four, then we'll just say return.

27
00:01:56,260 --> 00:01:57,100
‫True.

28
00:01:57,700 --> 00:02:04,450
‫So the other possibility is that temp is pointing to null pointer because it's an invalid index, in

29
00:02:04,450 --> 00:02:07,210
‫which case we'll say return false.

30
00:02:07,720 --> 00:02:11,130
‫So that is all of our code for the set function.

31
00:02:11,140 --> 00:02:13,960
‫We'll look at this code in a moment in VZ code.

32
00:02:13,960 --> 00:02:21,910
‫And when we do, we'll create this linked list and that will run set on the index of one and change

33
00:02:21,910 --> 00:02:23,950
‫this value to a four.

34
00:02:24,370 --> 00:02:27,430
‫So now let's flip over and take a look at this.

35
00:02:28,000 --> 00:02:31,090
‫So there is our set function there.

36
00:02:31,140 --> 00:02:35,080
‫I'm going to scroll up and we'll look at our main function.

37
00:02:35,260 --> 00:02:40,810
‫So that creates our linked list with the values of 11, three, 23 and seven.

38
00:02:41,170 --> 00:02:45,040
‫And then with this line, will print that out and I'll run this.

39
00:02:45,460 --> 00:02:49,870
‫And you can see over here that we have a linked list with those values.

40
00:02:50,410 --> 00:02:52,420
‫So now I'm going to come up here.

41
00:02:53,840 --> 00:03:00,710
‫And I'm going to run set at the index of one with a value of four, and I'll run this again.

42
00:03:01,280 --> 00:03:07,760
‫And now you can see that our linked list has values of 11, four, 23 and seven.

43
00:03:08,240 --> 00:03:12,110
‫And that is our function for set.

