1 00:00:01,140 --> 00:00:03,240 Iterating through the list is simple. 2 00:00:03,270 --> 00:00:07,330 You follow the next pointer from one link to the next. 3 00:00:07,350 --> 00:00:13,710 Before doing this, let's first fix the memory link introduced in the previous lecture. 4 00:00:13,830 --> 00:00:15,780 So above the main function. 5 00:00:17,460 --> 00:00:21,390 We're going to add the following function named bool. 6 00:00:21,540 --> 00:00:23,580 Remove hat here. 7 00:00:23,970 --> 00:00:28,290 So in this function we're going to add the if if statement. 8 00:00:28,320 --> 00:00:34,350 If no TR or the new tr equals the P hat. 9 00:00:35,880 --> 00:00:37,980 Don't return false. 10 00:00:41,220 --> 00:00:43,650 And then ask. 11 00:00:45,470 --> 00:00:46,370 Pete has. 12 00:00:48,470 --> 00:00:49,340 Please it. 13 00:00:50,570 --> 00:00:56,810 As always, I'm going to explain all of these quotes after writing this here and then. 14 00:00:57,740 --> 00:01:06,320 He said we're going to assign P hat to P, had the P next variable of pivot here, and then we're going 15 00:01:06,320 --> 00:01:07,810 to delete the P task. 16 00:01:12,000 --> 00:01:15,140 And we're going to return the p head. 17 00:01:15,150 --> 00:01:16,080 As you can see here. 18 00:01:16,080 --> 00:01:19,590 We're going to we have to return the p, we have to return the Boolean. 19 00:01:19,590 --> 00:01:22,500 So that's why we're going to use the. 20 00:01:24,150 --> 00:01:25,860 Logical operator here. 21 00:01:27,790 --> 00:01:29,350 No, Peter. 22 00:01:31,050 --> 00:01:39,300 So this function will remove the link at the beginning of the list and make sure that the P had. 23 00:01:40,050 --> 00:01:45,330 Pointer points to the next link, so which will become the new beginning of the list. 24 00:01:45,750 --> 00:01:48,150 So the function returns a pool. 25 00:01:48,390 --> 00:01:54,490 So the function returns a pool value indicating if there are any more links in the list. 26 00:01:54,510 --> 00:02:00,030 So if this function returns false, then it means the entire list has been deleted. 27 00:02:00,060 --> 00:02:07,830 So the first line of the code checks to see if the function has been called with an empty list. 28 00:02:07,830 --> 00:02:15,780 So once we reassured that the list has at least one link, we create a temporary copy of pointer. 29 00:02:16,170 --> 00:02:23,590 So the reason is that the intention is to delete the first item and make P hit point to the next item. 30 00:02:23,610 --> 00:02:26,940 And to do that, we have to do these steps in reverse. 31 00:02:26,970 --> 00:02:37,830 So firstly, make P had pointed the next item and then delete the P hit previously pointed on so that 32 00:02:37,830 --> 00:02:45,810 to delete the entire list you need to iterate through the links and this can be carried out using the 33 00:02:46,050 --> 00:02:46,800 while loop. 34 00:02:46,800 --> 00:02:51,870 So below this function we're going to add the destroy list function as well. 35 00:02:51,900 --> 00:02:55,110 Void destroy list. 36 00:02:55,860 --> 00:03:07,890 And while while this remove hit function returns true just while remove function returns true. 37 00:03:08,280 --> 00:03:13,350 And we're going to call the destroy list function here. 38 00:03:15,910 --> 00:03:16,480 Okay. 39 00:03:25,990 --> 00:03:26,270 Yeah. 40 00:03:27,130 --> 00:03:29,350 So you can now compile the code. 41 00:03:30,130 --> 00:03:30,880 Run it. 42 00:03:30,910 --> 00:03:32,730 However, you will not. 43 00:03:32,740 --> 00:03:39,580 But because all the course does is to create list and then delete deleted.