Let's add a simple main function.
We add parameters here and we're going to preheat provide with.
Basic input output using the include input output stream here and we're going to use the string in this
practice.
Practical example here.
So include string here.
So here about the main function.
Add a definition for the structure that represents a task in the list here.
Ask and ask one to your P next and string description.
Here.
So this has two members.
The guts of the object is the description item here.
So in our example.
Executing a task will involve the print printing, the description item to the console.
So in an actual project you will most likely have many items associated with the tasks and you may even
have member functions to execute the task.
But we have not covered the member functions in this course, which is the topic of another next lecture
here.
So the plumbing of the linked list is the other member P next here.
So not the task structure has not been completed defined at the point that the P next member is declared.
So this is not a problem because the P next here is a pointer.
So you cannot have a member of any undefined or a defined type because the compiler will not know how
much memory to allocate for it.
So you can have a pointer member to a partial defined type because a pointer member is the same size
irrespective of what it points to.
So if you know the first link in the list, then we can access the whole list.
And in our example, this will be a global variable.
So when constructing the list here.
The construction functions need to know the end of the list so they can attach a new link to the list.
Again, for convenience, we will make this global variable here and the following pointers after the
definition here.
Here.
The following pointers after a definition of the task pointer like that, hear it and looped.
BTR and task here.
The current.
No, Peter.
So as it stands here, if we execute this.
This code does nothing, but it's a good opportunity to compile the file to test that there are no errors
in our code share.
So let's add the task object to the list here.
So in this project, the next thing to do is to provide the code is to add add a new task to the task
list.
So this needs to create a new task object and initialize it appropriately and then add it to the list
by entering the last link in the list to point to a new link.
So above the main function here, add this queue task here void to.
Ask and consent.
Screen name.
Here.
So the parameter here is constant, this constant.
The parameter is constant because we will not change the parameter and we do not want to overheat of
a copy being made.
So by the way, I want to mention that this is not not just the variable, this is constant reference.
As you know, we make this ampersand before the variables to make them references.
So the first thing in this function, this function must do is create a new link.
So we're going to add the task pointer.
Ask P task.
Task.
The task.
Here.
New task.
And he task.
This operator.
You know it from the previous lectures.
Description and name.
P task for next year and we're going to assign it to New Peter.
So the first line creates a new link on the free store and following lines to initialize it.
So this is not necessarily the best way of initializing such an object.
And the beta mechanism is a constructor, so the constructors will be covered in next lectures here.
So notice that the P next near P next item is initialized to NULL.
Peter.
So this indicates that the link will be at the end of the list.
So the final part of this function adds the link to the list.
So this is, it makes the link the last in the list.
So however, if the list is empty, it means that this link is also the first link in the list.
So the code must perform both actions here and we're going to add.
Here.
If.
Here.
If New Peter.
He had.
Then he had.
He task.
The task.
Oops.
Okay.
He had is p task.
And then p current.
The test.
Else.
Here.
The key current.
E next.
And this equals to P task.
The current.
To task here.
So the first line of the code checks to see if the list is empty.
So if the if the P hit is null this, it means that there are no other links and so the current link
is the first link.
So and so both P heat and the P current are initialized to the new link pointer.
So if there are existing links in the string, the links has to be added to the last link.
So in the first class here, the first line, the first line makes the last link point to the new link
and the second line initialize the P current with the new link pointer, making the new link to the
last link for any new insertions to the list.
So the items are added to the list by calling this in the main function.
So in this example we will queue the tasks to a paper room.
So this involves removing the all well paper filling any holes in the vowel, sizing the vowel, and
then hanging the passage papers to the mouth.
So you have to do these tasks in this order so you cannot change the order.
So these tasks are ideal for a link list.
So in the main function we're going to use the queue task here.
As you know, we made this void function in this here we're going to use the queue task and remove all
wallpaper, for example.
And then we can use it again.
Fill holes.
Hair and size balls.
And to task the hang new hang new wallpapers.
So after the last line, the list has been created.
So the p heat variable points to the first item in the list, and you can access any other item in the
list simply by following the P next member from one list to the next.
So you can compile the code, but there is no output as you see here.
War says the code center is a memory leak, so the program has no code to delete the memory occupied
by the task objects.
So on the free store by the new operator here.
So in the next lecture we're going to create that the later task list command in C++.
So I'm waiting you in this lecture.