1 00:00:00,980 --> 00:00:03,370 Let's add a simple main function. 2 00:00:03,380 --> 00:00:09,620 We add parameters here and we're going to preheat provide with. 3 00:00:10,370 --> 00:00:19,430 Basic input output using the include input output stream here and we're going to use the string in this 4 00:00:19,430 --> 00:00:20,030 practice. 5 00:00:20,330 --> 00:00:22,130 Practical example here. 6 00:00:22,130 --> 00:00:24,830 So include string here. 7 00:00:26,160 --> 00:00:29,610 So here about the main function. 8 00:00:29,790 --> 00:00:37,860 Add a definition for the structure that represents a task in the list here. 9 00:00:38,940 --> 00:00:46,740 Ask and ask one to your P next and string description. 10 00:00:49,060 --> 00:00:49,500 Here. 11 00:00:50,530 --> 00:00:53,200 So this has two members. 12 00:00:53,200 --> 00:00:57,610 The guts of the object is the description item here. 13 00:00:57,610 --> 00:00:59,200 So in our example. 14 00:01:00,310 --> 00:01:07,320 Executing a task will involve the print printing, the description item to the console. 15 00:01:07,330 --> 00:01:14,620 So in an actual project you will most likely have many items associated with the tasks and you may even 16 00:01:14,620 --> 00:01:17,560 have member functions to execute the task. 17 00:01:17,560 --> 00:01:26,080 But we have not covered the member functions in this course, which is the topic of another next lecture 18 00:01:26,080 --> 00:01:26,560 here. 19 00:01:26,710 --> 00:01:32,860 So the plumbing of the linked list is the other member P next here. 20 00:01:32,860 --> 00:01:40,630 So not the task structure has not been completed defined at the point that the P next member is declared. 21 00:01:40,630 --> 00:01:45,040 So this is not a problem because the P next here is a pointer. 22 00:01:45,820 --> 00:01:54,940 So you cannot have a member of any undefined or a defined type because the compiler will not know how 23 00:01:54,940 --> 00:01:56,800 much memory to allocate for it. 24 00:01:56,800 --> 00:02:03,070 So you can have a pointer member to a partial defined type because a pointer member is the same size 25 00:02:03,070 --> 00:02:06,410 irrespective of what it points to. 26 00:02:06,430 --> 00:02:12,190 So if you know the first link in the list, then we can access the whole list. 27 00:02:12,310 --> 00:02:16,500 And in our example, this will be a global variable. 28 00:02:16,510 --> 00:02:19,510 So when constructing the list here. 29 00:02:20,610 --> 00:02:29,040 The construction functions need to know the end of the list so they can attach a new link to the list. 30 00:02:29,070 --> 00:02:36,120 Again, for convenience, we will make this global variable here and the following pointers after the 31 00:02:36,120 --> 00:02:37,650 definition here. 32 00:02:39,820 --> 00:02:40,240 Here. 33 00:02:41,500 --> 00:02:49,530 The following pointers after a definition of the task pointer like that, hear it and looped. 34 00:02:50,970 --> 00:02:53,820 BTR and task here. 35 00:02:57,600 --> 00:02:59,040 The current. 36 00:02:59,910 --> 00:03:01,270 No, Peter. 37 00:03:01,950 --> 00:03:06,540 So as it stands here, if we execute this. 38 00:03:07,410 --> 00:03:14,670 This code does nothing, but it's a good opportunity to compile the file to test that there are no errors 39 00:03:14,670 --> 00:03:15,960 in our code share. 40 00:03:16,350 --> 00:03:19,590 So let's add the task object to the list here. 41 00:03:19,590 --> 00:03:31,470 So in this project, the next thing to do is to provide the code is to add add a new task to the task 42 00:03:31,470 --> 00:03:31,670 list. 43 00:03:31,680 --> 00:03:39,780 So this needs to create a new task object and initialize it appropriately and then add it to the list 44 00:03:39,780 --> 00:03:43,860 by entering the last link in the list to point to a new link. 45 00:03:43,860 --> 00:03:51,870 So above the main function here, add this queue task here void to. 46 00:03:53,340 --> 00:03:55,440 Ask and consent. 47 00:03:56,430 --> 00:03:58,110 Screen name. 48 00:04:00,420 --> 00:04:00,840 Here. 49 00:04:02,050 --> 00:04:06,490 So the parameter here is constant, this constant. 50 00:04:06,610 --> 00:04:13,780 The parameter is constant because we will not change the parameter and we do not want to overheat of 51 00:04:13,780 --> 00:04:15,730 a copy being made. 52 00:04:16,180 --> 00:04:22,710 So by the way, I want to mention that this is not not just the variable, this is constant reference. 53 00:04:22,720 --> 00:04:29,380 As you know, we make this ampersand before the variables to make them references. 54 00:04:29,380 --> 00:04:37,480 So the first thing in this function, this function must do is create a new link. 55 00:04:37,510 --> 00:04:41,620 So we're going to add the task pointer. 56 00:04:41,890 --> 00:04:44,020 Ask P task. 57 00:04:45,110 --> 00:04:45,740 Task. 58 00:04:45,920 --> 00:04:47,090 The task. 59 00:04:48,770 --> 00:04:49,250 Here. 60 00:04:49,890 --> 00:04:50,870 New task. 61 00:04:53,180 --> 00:04:55,160 And he task. 62 00:04:56,170 --> 00:04:57,190 This operator. 63 00:04:57,190 --> 00:04:59,770 You know it from the previous lectures. 64 00:05:00,610 --> 00:05:03,010 Description and name. 65 00:05:05,200 --> 00:05:11,260 P task for next year and we're going to assign it to New Peter. 66 00:05:11,830 --> 00:05:19,750 So the first line creates a new link on the free store and following lines to initialize it. 67 00:05:19,750 --> 00:05:24,100 So this is not necessarily the best way of initializing such an object. 68 00:05:24,100 --> 00:05:31,450 And the beta mechanism is a constructor, so the constructors will be covered in next lectures here. 69 00:05:31,450 --> 00:05:37,000 So notice that the P next near P next item is initialized to NULL. 70 00:05:37,000 --> 00:05:37,810 Peter. 71 00:05:37,810 --> 00:05:42,460 So this indicates that the link will be at the end of the list. 72 00:05:42,550 --> 00:05:47,020 So the final part of this function adds the link to the list. 73 00:05:47,020 --> 00:05:50,590 So this is, it makes the link the last in the list. 74 00:05:50,590 --> 00:05:57,970 So however, if the list is empty, it means that this link is also the first link in the list. 75 00:05:57,970 --> 00:06:03,430 So the code must perform both actions here and we're going to add. 76 00:06:04,980 --> 00:06:05,610 Here. 77 00:06:09,600 --> 00:06:10,230 If. 78 00:06:12,470 --> 00:06:13,010 Here. 79 00:06:18,110 --> 00:06:20,900 If New Peter. 80 00:06:21,990 --> 00:06:22,860 He had. 81 00:06:24,700 --> 00:06:27,130 Then he had. 82 00:06:28,150 --> 00:06:29,080 He task. 83 00:06:30,720 --> 00:06:31,800 The task. 84 00:06:34,010 --> 00:06:34,490 Oops. 85 00:06:38,630 --> 00:06:39,190 Okay. 86 00:06:42,890 --> 00:06:46,070 He had is p task. 87 00:06:46,580 --> 00:06:49,640 And then p current. 88 00:06:50,380 --> 00:06:51,370 The test. 89 00:06:53,700 --> 00:06:54,420 Else. 90 00:06:56,740 --> 00:06:57,250 Here. 91 00:06:57,970 --> 00:06:59,770 The key current. 92 00:07:02,570 --> 00:07:03,500 E next. 93 00:07:04,160 --> 00:07:06,710 And this equals to P task. 94 00:07:08,200 --> 00:07:09,430 The current. 95 00:07:11,820 --> 00:07:13,740 To task here. 96 00:07:13,940 --> 00:07:20,360 So the first line of the code checks to see if the list is empty. 97 00:07:20,390 --> 00:07:30,440 So if the if the P hit is null this, it means that there are no other links and so the current link 98 00:07:30,440 --> 00:07:32,060 is the first link. 99 00:07:32,060 --> 00:07:39,580 So and so both P heat and the P current are initialized to the new link pointer. 100 00:07:39,590 --> 00:07:44,310 So if there are existing links in the string, the links has to be added to the last link. 101 00:07:44,330 --> 00:07:53,090 So in the first class here, the first line, the first line makes the last link point to the new link 102 00:07:53,090 --> 00:08:00,710 and the second line initialize the P current with the new link pointer, making the new link to the 103 00:08:00,710 --> 00:08:03,980 last link for any new insertions to the list. 104 00:08:04,520 --> 00:08:11,680 So the items are added to the list by calling this in the main function. 105 00:08:11,690 --> 00:08:16,150 So in this example we will queue the tasks to a paper room. 106 00:08:16,160 --> 00:08:23,330 So this involves removing the all well paper filling any holes in the vowel, sizing the vowel, and 107 00:08:23,330 --> 00:08:25,800 then hanging the passage papers to the mouth. 108 00:08:25,820 --> 00:08:31,670 So you have to do these tasks in this order so you cannot change the order. 109 00:08:32,060 --> 00:08:36,030 So these tasks are ideal for a link list. 110 00:08:36,050 --> 00:08:39,770 So in the main function we're going to use the queue task here. 111 00:08:40,490 --> 00:08:49,640 As you know, we made this void function in this here we're going to use the queue task and remove all 112 00:08:49,640 --> 00:08:51,710 wallpaper, for example. 113 00:08:52,550 --> 00:08:55,280 And then we can use it again. 114 00:08:55,670 --> 00:08:57,500 Fill holes. 115 00:08:59,080 --> 00:09:02,410 Hair and size balls. 116 00:09:03,740 --> 00:09:10,310 And to task the hang new hang new wallpapers. 117 00:09:11,540 --> 00:09:16,310 So after the last line, the list has been created. 118 00:09:17,310 --> 00:09:23,220 So the p heat variable points to the first item in the list, and you can access any other item in the 119 00:09:23,220 --> 00:09:28,470 list simply by following the P next member from one list to the next. 120 00:09:28,470 --> 00:09:32,730 So you can compile the code, but there is no output as you see here. 121 00:09:32,760 --> 00:09:39,570 War says the code center is a memory leak, so the program has no code to delete the memory occupied 122 00:09:39,570 --> 00:09:41,030 by the task objects. 123 00:09:41,040 --> 00:09:45,180 So on the free store by the new operator here. 124 00:09:45,180 --> 00:09:53,460 So in the next lecture we're going to create that the later task list command in C++. 125 00:09:53,460 --> 00:09:55,680 So I'm waiting you in this lecture.