1
00:00:00,640 --> 00:00:08,020
A common requirement is to have a collection that can be an arbitrary size and can grow and shrink at

2
00:00:08,020 --> 00:00:08,800
runtime.

3
00:00:08,800 --> 00:00:15,880
So the C plus plus standard library provides a various classes to allow you to do this and will be described

4
00:00:15,880 --> 00:00:17,290
in next lecture, of course.

5
00:00:17,290 --> 00:00:25,240
But in this lecture we will create an examples that illustrates some of the principles of how these

6
00:00:25,240 --> 00:00:28,570
standard collections are implemented here.

7
00:00:28,570 --> 00:00:35,890
So in general, you should use the C plus plus standard library classes rather than implementing your

8
00:00:35,890 --> 00:00:37,090
own classes here.

9
00:00:37,510 --> 00:00:45,670
So further, the standard library classes encapsulate code together in a class, and since we have not

10
00:00:45,670 --> 00:00:52,480
covered classes yet, this in this lecture that we're going to create some code.

11
00:00:52,510 --> 00:00:58,960
In this code we're going to use functions that potentially can be called incorrectly.

12
00:00:58,960 --> 00:01:03,410
So you should regard this examples as just that example code here.

13
00:01:03,410 --> 00:01:06,800
So a linked list is a common data structure here.

14
00:01:06,800 --> 00:01:13,190
So these are typically used for queues where the order of items is important.

15
00:01:13,190 --> 00:01:21,260
So for example, a first in, first out queue, where the tasks are performed in the order that they

16
00:01:21,260 --> 00:01:23,180
are inserted in the queue here.

17
00:01:23,300 --> 00:01:31,100
So in this example, each task is represented as a structure that contains the task description and

18
00:01:31,100 --> 00:01:34,070
the pointer to the next task to be performed.

19
00:01:34,070 --> 00:01:42,830
So if a pointer to the next task is nullptr, then this means that the current task is the last task

20
00:01:42,830 --> 00:01:45,230
in the list here.

21
00:01:45,230 --> 00:01:48,500
So struct we're going to create a new struct here.

22
00:01:48,530 --> 00:01:54,290
Of course outside the here struct task here.

23
00:01:55,650 --> 00:02:01,650
And here we're going to task P next and.

24
00:02:02,840 --> 00:02:04,670
We can create another string here.

25
00:02:09,750 --> 00:02:10,410
Here.

26
00:02:10,560 --> 00:02:19,260
So recall this from the last chapter that you can access members of structure using the dot operator

27
00:02:19,260 --> 00:02:29,760
here so we can make it like that task that or let's create a task item and item that description here.

28
00:02:29,760 --> 00:02:33,270
As you can see, we can access their members.

29
00:02:33,270 --> 00:02:36,240
So in this case, the compiler will create a string.

30
00:02:37,080 --> 00:02:40,140
A string object initialized with the string literal.

31
00:02:40,800 --> 00:02:47,430
That means here we're going to initialize it with to something here.

32
00:02:48,360 --> 00:02:54,990
So and it will assign to the description member of the instance called item.

33
00:02:54,990 --> 00:02:58,380
So you can also create a task on the free storage.

34
00:02:59,260 --> 00:03:03,130
Using the new operator like that here, for example.

35
00:03:03,130 --> 00:03:08,350
Task P task and new task here.

36
00:03:09,070 --> 00:03:09,580
Oops.

37
00:03:09,870 --> 00:03:10,750
Uh, task.

38
00:03:11,450 --> 00:03:11,870
Here.

39
00:03:11,870 --> 00:03:23,320
And after using the object, after using the object object, you can delete by this.

40
00:03:23,330 --> 00:03:24,260
Delete.

41
00:03:25,210 --> 00:03:26,740
P task here.

42
00:03:26,980 --> 00:03:27,610
P task.

43
00:03:28,690 --> 00:03:37,720
So here in this case, the members of the object have to be accessed through the pointer and Cplusplus

44
00:03:37,720 --> 00:03:47,440
provides this operator here like that, the minus operator and the right, uh, greater than operator

45
00:03:47,440 --> 00:03:48,010
here.

46
00:03:48,530 --> 00:03:52,690
Uh, this operator gives you this access here.

47
00:03:52,810 --> 00:03:53,800
P task.

48
00:03:54,100 --> 00:03:56,000
P Task here.

49
00:03:56,380 --> 00:03:57,490
Description.

50
00:03:57,850 --> 00:03:59,140
As you can see here.

51
00:03:59,140 --> 00:04:01,120
And do something.

52
00:04:02,730 --> 00:04:03,120
Here.

53
00:04:03,330 --> 00:04:11,730
So here the description member here, here, The description member is assigned to the string.

54
00:04:11,730 --> 00:04:14,970
So not that the science task is a structure.

55
00:04:15,640 --> 00:04:18,160
There is no access restrictions.

56
00:04:18,160 --> 00:04:23,990
So something that is important with classes and described in next lecture here.

57
00:04:24,010 --> 00:04:30,790
So in next in this lecture, we're going to create some project that is going to.

58
00:04:35,650 --> 00:04:38,020
Use this task struct here.

59
00:04:39,520 --> 00:04:41,650
And, um.

60
00:04:42,190 --> 00:04:47,110
And we're going to make the strings and the task next pointers here.

61
00:04:47,110 --> 00:04:49,570
So I'm waiting you in next lecture.
