WEBVTT

00:00.640 --> 00:08.020
A common requirement is to have a collection that can be an arbitrary size and can grow and shrink at

00:08.020 --> 00:08.800
runtime.

00:08.800 --> 00:15.880
So the C plus plus standard library provides a various classes to allow you to do this and will be described

00:15.880 --> 00:17.290
in next lecture, of course.

00:17.290 --> 00:25.240
But in this lecture we will create an examples that illustrates some of the principles of how these

00:25.240 --> 00:28.570
standard collections are implemented here.

00:28.570 --> 00:35.890
So in general, you should use the C plus plus standard library classes rather than implementing your

00:35.890 --> 00:37.090
own classes here.

00:37.510 --> 00:45.670
So further, the standard library classes encapsulate code together in a class, and since we have not

00:45.670 --> 00:52.480
covered classes yet, this in this lecture that we're going to create some code.

00:52.510 --> 00:58.960
In this code we're going to use functions that potentially can be called incorrectly.

00:58.960 --> 01:03.410
So you should regard this examples as just that example code here.

01:03.410 --> 01:06.800
So a linked list is a common data structure here.

01:06.800 --> 01:13.190
So these are typically used for queues where the order of items is important.

01:13.190 --> 01:21.260
So for example, a first in, first out queue, where the tasks are performed in the order that they

01:21.260 --> 01:23.180
are inserted in the queue here.

01:23.300 --> 01:31.100
So in this example, each task is represented as a structure that contains the task description and

01:31.100 --> 01:34.070
the pointer to the next task to be performed.

01:34.070 --> 01:42.830
So if a pointer to the next task is nullptr, then this means that the current task is the last task

01:42.830 --> 01:45.230
in the list here.

01:45.230 --> 01:48.500
So struct we're going to create a new struct here.

01:48.530 --> 01:54.290
Of course outside the here struct task here.

01:55.650 --> 02:01.650
And here we're going to task P next and.

02:02.840 --> 02:04.670
We can create another string here.

02:09.750 --> 02:10.410
Here.

02:10.560 --> 02:19.260
So recall this from the last chapter that you can access members of structure using the dot operator

02:19.260 --> 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.

02:29.760 --> 02:33.270
As you can see, we can access their members.

02:33.270 --> 02:36.240
So in this case, the compiler will create a string.

02:37.080 --> 02:40.140
A string object initialized with the string literal.

02:40.800 --> 02:47.430
That means here we're going to initialize it with to something here.

02:48.360 --> 02:54.990
So and it will assign to the description member of the instance called item.

02:54.990 --> 02:58.380
So you can also create a task on the free storage.

02:59.260 --> 03:03.130
Using the new operator like that here, for example.

03:03.130 --> 03:08.350
Task P task and new task here.

03:09.070 --> 03:09.580
Oops.

03:09.870 --> 03:10.750
Uh, task.

03:11.450 --> 03:11.870
Here.

03:11.870 --> 03:23.320
And after using the object, after using the object object, you can delete by this.

03:23.330 --> 03:24.260
Delete.

03:25.210 --> 03:26.740
P task here.

03:26.980 --> 03:27.610
P task.

03:28.690 --> 03:37.720
So here in this case, the members of the object have to be accessed through the pointer and Cplusplus

03:37.720 --> 03:47.440
provides this operator here like that, the minus operator and the right, uh, greater than operator

03:47.440 --> 03:48.010
here.

03:48.530 --> 03:52.690
Uh, this operator gives you this access here.

03:52.810 --> 03:53.800
P task.

03:54.100 --> 03:56.000
P Task here.

03:56.380 --> 03:57.490
Description.

03:57.850 --> 03:59.140
As you can see here.

03:59.140 --> 04:01.120
And do something.

04:02.730 --> 04:03.120
Here.

04:03.330 --> 04:11.730
So here the description member here, here, The description member is assigned to the string.

04:11.730 --> 04:14.970
So not that the science task is a structure.

04:15.640 --> 04:18.160
There is no access restrictions.

04:18.160 --> 04:23.990
So something that is important with classes and described in next lecture here.

04:24.010 --> 04:30.790
So in next in this lecture, we're going to create some project that is going to.

04:35.650 --> 04:38.020
Use this task struct here.

04:39.520 --> 04:41.650
And, um.

04:42.190 --> 04:47.110
And we're going to make the strings and the task next pointers here.

04:47.110 --> 04:49.570
So I'm waiting you in next lecture.
