A common requirement is to have a collection that can be an arbitrary size and can grow and shrink at
runtime.
So the C plus plus standard library provides a various classes to allow you to do this and will be described
in next lecture, of course.
But in this lecture we will create an examples that illustrates some of the principles of how these
standard collections are implemented here.
So in general, you should use the C plus plus standard library classes rather than implementing your
own classes here.
So further, the standard library classes encapsulate code together in a class, and since we have not
covered classes yet, this in this lecture that we're going to create some code.
In this code we're going to use functions that potentially can be called incorrectly.
So you should regard this examples as just that example code here.
So a linked list is a common data structure here.
So these are typically used for queues where the order of items is important.
So for example, a first in, first out queue, where the tasks are performed in the order that they
are inserted in the queue here.
So in this example, each task is represented as a structure that contains the task description and
the pointer to the next task to be performed.
So if a pointer to the next task is nullptr, then this means that the current task is the last task
in the list here.
So struct we're going to create a new struct here.
Of course outside the here struct task here.
And here we're going to task P next and.
We can create another string here.
Here.
So recall this from the last chapter that you can access members of structure using the dot operator
here so we can make it like that task that or let's create a task item and item that description here.
As you can see, we can access their members.
So in this case, the compiler will create a string.
A string object initialized with the string literal.
That means here we're going to initialize it with to something here.
So and it will assign to the description member of the instance called item.
So you can also create a task on the free storage.
Using the new operator like that here, for example.
Task P task and new task here.
Oops.
Uh, task.
Here.
And after using the object, after using the object object, you can delete by this.
Delete.
P task here.
P task.
So here in this case, the members of the object have to be accessed through the pointer and Cplusplus
provides this operator here like that, the minus operator and the right, uh, greater than operator
here.
Uh, this operator gives you this access here.
P task.
P Task here.
Description.
As you can see here.
And do something.
Here.
So here the description member here, here, The description member is assigned to the string.
So not that the science task is a structure.
There is no access restrictions.
So something that is important with classes and described in next lecture here.
So in next in this lecture, we're going to create some project that is going to.
Use this task struct here.
And, um.
And we're going to make the strings and the task next pointers here.
So I'm waiting you in next lecture.