Let's add a simple main function without parameters here and we're going to print provide a width.
Basic input output using the include input output stream here and we're going to use the string in this
practical practical example here.
So include string here.
So here above the main function, add a definition for the structure that represents a task in the list
here.
Task and task pointer here.
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, we most likely will 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 the task structure has not been completely 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 data member of any undefined or a partially 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 we 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 the definition of the task pointer like that.
Here it and nullptr.
VTR and task here.
He 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 here.
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, uh, 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 adding the last link in the list to point to a new link.
So above the main function here, add this new task here void queue.
Task and const.
Spring name.
Here.
So the parameter here is const this const the parameter is const 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 the not just a const variable, this is const reference.
As you know, we make this ampersand before the variables to make them references.
So the first thing in this function, the function this function must do is create a new link.
So we're going to add the task pointer task P task.
Task T task.
Here.
New task.
And task.
This operator.
You know it from the previous lectures.
Description and name.
P task.
P next year and we can assign it to nullptr.
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 a better mechanism is a constructor, so the constructors will be covered in next lectures here.
So notice that the P next year P next item is initialized to nullptr.
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 the 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.
Nullptr.
He had.
Then he had.
He task.
Oops.
Okay.
T hat is p task and then p current.
He test?
Else.
Here the current.
He next and it equals to p task.
The current.
The 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 the there are no other links.
And so the current link is the first link.
So and so both P hit 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 s 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 wallpaper room.
So this involves removing the old wallpaper, filling any holes in the wall, sizing the wall and then
hanging the passage wallpapers to the wall.
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 a queue task here.
As you know, we made this void function in this here.
We're going to use the queue task and remove old wallpaper for example, and then we're going to use
it again.
Fill holes.
Here and size walls.
And to task the hang new hang new wallpapers.
So after the last line, the list has been created.
So the heat variable points to the first item in the list and you can access any other item in the list
simply by following the next member from one list to the next so you can compile the code.
But there is no output as you see here.
Worse, as the code center is a memory leak, so the program has no code to delete the memory occupied
by the task object.
So on the free store by the new operator here.
So in next lecture we're going to create that delete the task list command in C plus plus.
So I'm waiting you in next lecture.