1
00:00:01,180 --> 00:00:09,250
So the next step is to iterate the list from the first link, following each next pointer until we get

2
00:00:09,250 --> 00:00:10,640
to the end of the list.

3
00:00:10,660 --> 00:00:14,940
So for each link access the task should be executed here.

4
00:00:14,950 --> 00:00:22,390
So start by writing a function that performs the execution, by printing out the description of the

5
00:00:22,390 --> 00:00:26,690
task and then returning the pointer to the next task.

6
00:00:26,710 --> 00:00:34,450
So here, just above the main function, we're going to add the task that we're going to add the function

7
00:00:35,230 --> 00:00:39,460
that will return the task here and execute this.

8
00:00:40,000 --> 00:00:49,390
This function will be named at execute task in a constant task pointer P task.

9
00:00:49,840 --> 00:00:51,130
So here.

10
00:00:53,240 --> 00:00:56,540
The if the nullptr nullptr.

11
00:00:57,590 --> 00:00:59,090
Equals to P task.

12
00:00:59,810 --> 00:01:02,430
Then return the nullptr.

13
00:01:03,760 --> 00:01:08,230
See out here executing the.

14
00:01:09,260 --> 00:01:12,620
Finally, we've writing some outputs here.

15
00:01:15,690 --> 00:01:16,260
Here.

16
00:01:19,570 --> 00:01:21,460
And task.

17
00:01:22,580 --> 00:01:25,340
This operator here and description.

18
00:01:26,870 --> 00:01:28,580
And of course, in line here.

19
00:01:30,420 --> 00:01:32,650
And we're going to return the task object.

20
00:01:32,700 --> 00:01:33,360
A task?

21
00:01:33,390 --> 00:01:35,070
Uh, not object task.

22
00:01:35,460 --> 00:01:39,510
The struct here, as you can see here, return the task.

23
00:01:39,510 --> 00:01:40,570
P task.

24
00:01:40,840 --> 00:01:45,510
Task and p p next.

25
00:01:46,080 --> 00:01:54,060
So the parameter here is marked as constant because we will not change the task object pointed to by

26
00:01:54,060 --> 00:01:54,660
the pointer.

27
00:01:54,660 --> 00:02:00,300
So this indicates that the compiler that if the code does try to change the object, there is an usually

28
00:02:00,300 --> 00:02:07,170
here the first line checks to make sure that the function is not called with the null pointer.

29
00:02:07,170 --> 00:02:09,240
So it was done following line.

30
00:02:09,270 --> 00:02:15,390
Would the reference invalid pointer and cause a memory access fault?

31
00:02:15,390 --> 00:02:22,290
So the last line returns the pointer to the next link, which could be nullptr for the last link in

32
00:02:22,290 --> 00:02:26,640
the list so that the function can be called in loop.

33
00:02:26,640 --> 00:02:28,620
So after this function.

34
00:02:29,620 --> 00:02:32,900
We're going to add another function here.

35
00:02:32,920 --> 00:02:36,220
Void function named execute all.

36
00:02:36,880 --> 00:02:39,550
So here task.

37
00:02:41,310 --> 00:02:42,540
Task here.

38
00:02:43,170 --> 00:02:44,040
The task.

39
00:02:46,240 --> 00:02:47,710
And P hat.

40
00:02:49,210 --> 00:02:49,690
What's.

41
00:02:50,650 --> 00:02:52,630
The task assigned to p hat.

42
00:02:53,140 --> 00:03:00,580
And while the p task is not equal to nullptr, PTA is not equal to nullptr.

43
00:03:01,550 --> 00:03:01,970
Here.

44
00:03:02,960 --> 00:03:05,270
We're going to assign task.

45
00:03:06,760 --> 00:03:12,460
Execute task and we're going to pass the p task itself here.

46
00:03:12,460 --> 00:03:15,790
So this code starts at beginning.

47
00:03:16,140 --> 00:03:25,430
Uh, p hat and calls the execute task on each list in the list until the function returns the nullptr.

48
00:03:25,450 --> 00:03:32,110
So we're going to add the call function towards the end of the main function here.

49
00:03:32,980 --> 00:03:33,760
Okay.

50
00:03:36,210 --> 00:03:43,220
Going to first execute all function and execute all function, and we're going to call the destroy.

51
00:03:44,290 --> 00:03:46,110
Destroy a okay.

52
00:03:46,990 --> 00:03:47,560
Yeah.

53
00:03:48,220 --> 00:03:49,900
Make it upper.

54
00:03:51,480 --> 00:03:51,870
Go here.

55
00:03:51,870 --> 00:04:00,960
We're going to call destroy list function here so we can now compile and run our code.

56
00:04:00,960 --> 00:04:05,730
But we have a okay, we can now compile and run the code here.

57
00:04:10,330 --> 00:04:12,010
The result will be like this.

58
00:04:12,010 --> 00:04:21,550
But in this here, in this lecture, we're going to add another, uh, items here in this struct here

59
00:04:21,550 --> 00:04:26,170
and make it more, uh, rich with objects here.

60
00:04:26,170 --> 00:04:31,330
So in next lecture we're going to add the items, insert items to the struct.
