1 00:00:00,710 --> 00:00:07,760 The common requirement is to have a collection that can be an aperture size and can grow and shrink 2 00:00:07,790 --> 00:00:08,870 at runtime. 3 00:00:08,870 --> 00:00:15,950 So the C++ Standard library provides various classes to allow you to do this, and they will be described 4 00:00:15,950 --> 00:00:17,420 in next lecture, of course. 5 00:00:17,420 --> 00:00:26,120 But in this lecture we will create an example that illustrates some of the principles of how these standard 6 00:00:26,120 --> 00:00:28,610 collections are implemented here. 7 00:00:28,610 --> 00:00:36,710 So in general, you should use the C++ standard library classes rather than implementing your own classes 8 00:00:36,710 --> 00:00:37,100 here. 9 00:00:37,730 --> 00:00:45,740 So further, the standard library classes encapsulate code together in a class, and since we have not 10 00:00:45,740 --> 00:00:52,610 covered classes yet, this in this lecture that we're gonna create some code. 11 00:00:52,640 --> 00:00:59,000 In this code we're going to use functions that potentially can be called incorrectly. 12 00:00:59,000 --> 00:01:03,380 So you should regard this example as just that example code here. 13 00:01:03,380 --> 00:01:06,740 So a linked list is a common data structure here. 14 00:01:06,740 --> 00:01:13,160 So these are typically used for queues where the order of items is important. 15 00:01:13,160 --> 00:01:21,500 So for example, a first in first out queue where the tasks are performed in the order that they are 16 00:01:21,500 --> 00:01:23,060 inserted in the queue here. 17 00:01:23,420 --> 00:01:31,070 So in this example, each task is represented as a structure that contains the task description and 18 00:01:31,070 --> 00:01:34,040 the pointer to the next task to be performed. 19 00:01:34,040 --> 00:01:42,230 So if a pointer to the next stack task is not here, then this means that the current task is the last 20 00:01:42,230 --> 00:01:45,080 task in the list here. 21 00:01:45,320 --> 00:01:54,290 So struct, we're going to create a new struct here of course outside the here struct task here. 22 00:01:55,750 --> 00:02:01,660 And here we're going to task the next and. 23 00:02:03,000 --> 00:02:04,710 We're going to create another string here. 24 00:02:09,880 --> 00:02:10,420 Here. 25 00:02:10,780 --> 00:02:19,360 So recall this from the last chapter that you can access members of structure using the dot operator 26 00:02:19,360 --> 00:02:29,830 here so we can make it like that task that or let's create a task item and item that description here. 27 00:02:29,830 --> 00:02:33,340 As you can see, we can access their members. 28 00:02:33,340 --> 00:02:40,210 So in this case, the compiler will create a string string object initialized with the string literal. 29 00:02:40,930 --> 00:02:47,410 That means here we're going to initialize it with two something here. 30 00:02:48,700 --> 00:02:55,060 So and it will assign to the description member of the instance called item. 31 00:02:55,060 --> 00:02:58,390 So you can also create a task on the free storage. 32 00:02:59,330 --> 00:03:10,760 Using the new operator like that here, for example, Task P Task and New Task Year Ops task. 33 00:03:11,490 --> 00:03:12,000 Here. 34 00:03:12,090 --> 00:03:15,210 And after using the object. 35 00:03:15,210 --> 00:03:17,970 After using the object. 36 00:03:18,360 --> 00:03:23,460 Object you can delete by this. 37 00:03:23,460 --> 00:03:24,360 Delete. 38 00:03:25,280 --> 00:03:27,620 B task here, B task. 39 00:03:28,880 --> 00:03:36,340 So here in this case, the members of the object have to be accessed through the pointer. 40 00:03:36,350 --> 00:03:46,950 And C++ provides this operator here like that, the minus operator and the right greater than. 41 00:03:46,970 --> 00:03:48,050 Operator here. 42 00:03:48,830 --> 00:03:52,730 This operator gives you this access here. 43 00:03:52,940 --> 00:04:01,160 P task P task here description as you can see here and do something. 44 00:04:02,770 --> 00:04:03,220 Here. 45 00:04:03,490 --> 00:04:11,800 So here the description member here, the description member is assigned to the string. 46 00:04:11,800 --> 00:04:15,010 So not that the science task is a structure. 47 00:04:15,770 --> 00:04:18,260 There is no access restrictions. 48 00:04:18,260 --> 00:04:23,960 So something that is important with classes and described in next lecture here. 49 00:04:24,200 --> 00:04:30,950 So in next in this lecture, we're going to create some project that is going to. 50 00:04:35,810 --> 00:04:38,090 Use this task structure here. 51 00:04:39,650 --> 00:04:41,840 And, um. 52 00:04:42,350 --> 00:04:47,150 And we're going to make the strings, and that has, uh, p next pointers here. 53 00:04:47,150 --> 00:04:49,610 So I'm waiting you in the next lecture.