Iterating through the list is simple.
You follow the next pointer from one link to the next.
Before doing this, let's first fix the memory link introduced in the previous lecture.
So above the main function.
We're going to add the following function named bool.
Remove hat here.
So in this function we're going to add the if if statement.
If no TR or the new tr equals the P hat.
Don't return false.
And then ask.
Pete has.
Please it.
As always, I'm going to explain all of these quotes after writing this here and then.
He said we're going to assign P hat to P, had the P next variable of pivot here, and then we're going
to delete the P task.
And we're going to return the p head.
As you can see here.
We're going to we have to return the p, we have to return the Boolean.
So that's why we're going to use the.
Logical operator here.
No, Peter.
So this function will remove the link at the beginning of the list and make sure that the P had.
Pointer points to the next link, so which will become the new beginning of the list.
So the function returns a pool.
So the function returns a pool value indicating if there are any more links in the list.
So if this function returns false, then it means the entire list has been deleted.
So the first line of the code checks to see if the function has been called with an empty list.
So once we reassured that the list has at least one link, we create a temporary copy of pointer.
So the reason is that the intention is to delete the first item and make P hit point to the next item.
And to do that, we have to do these steps in reverse.
So firstly, make P had pointed the next item and then delete the P hit previously pointed on so that
to delete the entire list you need to iterate through the links and this can be carried out using the
while loop.
So below this function we're going to add the destroy list function as well.
Void destroy list.
And while while this remove hit function returns true just while remove function returns true.
And we're going to call the destroy list function here.
Okay.
Yeah.
So you can now compile the code.
Run it.
However, you will not.
But because all the course does is to create list and then delete deleted.