1 00:00:00,550 --> 00:00:01,690 Hello, my name is Stephan. 2 00:00:01,690 --> 00:00:07,180 And in this lecture of our course, we will develop a singly linked list in ADT. 3 00:00:07,330 --> 00:00:08,740 So let's get started. 4 00:00:21,330 --> 00:00:27,320 So the single linked list, also known as just the linked list here. 5 00:00:27,360 --> 00:00:28,440 Linked. 6 00:00:31,630 --> 00:00:32,950 Linked list. 7 00:00:35,480 --> 00:00:39,470 Is a sequence of items that is linked with each other. 8 00:00:39,470 --> 00:00:41,000 It's actually a chaining of nodes. 9 00:00:41,000 --> 00:00:45,950 So where each node contains the items value and the next pointer. 10 00:00:45,950 --> 00:00:55,310 So in other words, each item in the linked list has a link to its next item on sequence. 11 00:00:55,520 --> 00:01:04,400 The thing is that differs between the linked list and the node chain is that the linked list has a heat. 12 00:01:08,080 --> 00:01:10,900 Has a head and a tail. 13 00:01:11,170 --> 00:01:15,160 So has a head and tail pointer. 14 00:01:15,160 --> 00:01:16,960 So the heat. 15 00:01:16,990 --> 00:01:21,700 The heat here informs the heat here. 16 00:01:22,740 --> 00:01:27,540 Informs the first item and the tail here. 17 00:01:28,520 --> 00:01:32,350 Informs the last item in the linked list. 18 00:01:32,360 --> 00:01:40,280 So similar to the list ADT, we have learned earlier the linked list has actually let me write it here. 19 00:01:40,610 --> 00:01:42,980 Linked list has get. 20 00:01:45,130 --> 00:01:49,780 We link this has get insert insert. 21 00:01:51,840 --> 00:01:52,650 The search. 22 00:01:59,420 --> 00:02:03,970 And lastly remove operations re. 23 00:02:04,720 --> 00:02:05,350 Move. 24 00:02:08,260 --> 00:02:16,990 So we are all of the operations have the same functionality compared to that we learned previously list 25 00:02:16,990 --> 00:02:17,680 here. 26 00:02:18,550 --> 00:02:22,510 So however, since we now have the heat here. 27 00:02:22,630 --> 00:02:24,010 The heat. 28 00:02:24,740 --> 00:02:26,480 And tell. 29 00:02:27,910 --> 00:02:30,490 Pointers for these head and tail are pointers actually. 30 00:02:30,490 --> 00:02:34,490 So we will also create other operations that these are. 31 00:02:34,510 --> 00:02:38,350 We will create the insert hale in. 32 00:02:40,380 --> 00:02:41,970 Insert. 33 00:02:42,510 --> 00:02:44,610 So we're going to create the insert. 34 00:02:44,640 --> 00:02:45,510 Hit. 35 00:02:45,510 --> 00:02:46,800 Insert. 36 00:02:46,830 --> 00:02:47,730 Hit. 37 00:02:49,670 --> 00:02:54,500 We will also create the insert tail in. 38 00:02:55,360 --> 00:02:56,650 Swordtail. 39 00:02:58,740 --> 00:03:02,430 And we will also create the remove head and remove tail here. 40 00:03:02,430 --> 00:03:03,960 So remove. 41 00:03:06,060 --> 00:03:06,720 Heath. 42 00:03:12,940 --> 00:03:14,800 And remove tail. 43 00:03:19,240 --> 00:03:20,110 Remove tail. 44 00:03:23,580 --> 00:03:24,120 Here. 45 00:03:24,240 --> 00:03:26,780 So now the declaration here. 46 00:03:26,790 --> 00:03:34,050 So we we will declare all of these items in our linked list here. 47 00:03:34,050 --> 00:03:40,410 So we will declare all of these items here in this section of our course. 48 00:03:40,410 --> 00:03:42,510 So actually, let's delete. 49 00:03:43,420 --> 00:03:44,920 Let's delete this. 50 00:03:46,270 --> 00:03:49,120 That we want to use here for now. 51 00:03:49,510 --> 00:03:50,980 Also, delete this. 52 00:03:51,730 --> 00:03:52,960 Delete this. 53 00:03:55,000 --> 00:03:57,790 I'll delete all of them so we won't use them, actually. 54 00:03:59,030 --> 00:04:00,080 In this lecture. 55 00:04:05,300 --> 00:04:05,930 Here. 56 00:04:13,570 --> 00:04:15,520 And we will show you now here. 57 00:04:15,520 --> 00:04:24,280 So this little, this, this and here, I'm not deleting this because I will show and make the checkboxes 58 00:04:24,280 --> 00:04:24,760 around them. 59 00:04:24,760 --> 00:04:29,590 So we will notify that we already created that here. 60 00:04:29,590 --> 00:04:34,780 So now firstly, we will create a linked list class. 61 00:04:34,780 --> 00:04:43,810 So we will also use the template template Typename t typename t here and now. 62 00:04:43,810 --> 00:04:50,920 After that we're going to create the class class linked list. 63 00:04:50,920 --> 00:04:53,260 And here we will private. 64 00:04:53,260 --> 00:04:57,910 We will create my count so we will make private my count here. 65 00:04:57,910 --> 00:04:59,350 So this is going to be an integer. 66 00:05:00,680 --> 00:05:06,470 And will all other operators, we will define it public here, public. 67 00:05:06,470 --> 00:05:09,770 So we will first need to the first node in the list. 68 00:05:10,280 --> 00:05:12,260 It's our new list empty. 69 00:05:12,260 --> 00:05:19,130 So node here t template and pointer it. 70 00:05:19,880 --> 00:05:22,190 So here, as you can see, we got an error here. 71 00:05:22,190 --> 00:05:24,800 That's because no template named node here. 72 00:05:24,800 --> 00:05:33,680 So what we will create it and fix it now while we are writing our code and after that we are going to 73 00:05:33,680 --> 00:05:35,360 create the node here. 74 00:05:35,360 --> 00:05:35,770 T. 75 00:05:38,040 --> 00:05:38,640 Or. 76 00:05:41,170 --> 00:05:42,130 Yeah, we will. 77 00:05:42,130 --> 00:05:44,680 We will use the previously created codes. 78 00:05:45,730 --> 00:05:49,390 That After that we will add this code on it. 79 00:05:49,390 --> 00:05:51,340 So firstly, we will create a tail. 80 00:05:52,200 --> 00:05:56,340 So here and we will also create a constructor, of course. 81 00:05:56,340 --> 00:06:02,040 So Linkedlist constructor here and we will get operation. 82 00:06:02,040 --> 00:06:05,430 So the get operation is going to be not here to. 83 00:06:07,360 --> 00:06:08,740 And get. 84 00:06:09,840 --> 00:06:10,050 Yet. 85 00:06:10,050 --> 00:06:12,840 It's going to be get index integer index. 86 00:06:13,380 --> 00:06:15,540 We will also use the insert. 87 00:06:15,540 --> 00:06:25,110 So now actually, let me open our lectures that we did some projects in previous lectures, the previous 88 00:06:25,110 --> 00:06:33,210 section, and at that section we had some text that we have written in last lecture. 89 00:06:33,360 --> 00:06:37,200 So this is the A to creating and changing note with different data types. 90 00:06:37,200 --> 00:06:41,250 So we will copy this and paste it here. 91 00:06:43,710 --> 00:06:49,740 Here and we will get this linked list after the node class here. 92 00:06:49,740 --> 00:06:51,270 After the node class. 93 00:06:52,780 --> 00:06:53,860 Also delete this template. 94 00:06:53,860 --> 00:07:01,120 So after the node class and print node we will create, we will paste this, our linked list here. 95 00:07:01,150 --> 00:07:02,770 We will also need two template here. 96 00:07:02,770 --> 00:07:05,290 So template type name. 97 00:07:07,150 --> 00:07:13,450 T so template typename t here. 98 00:07:13,630 --> 00:07:15,130 And after that. 99 00:07:18,640 --> 00:07:21,550 So we have a get here. 100 00:07:21,550 --> 00:07:24,190 We get, get, get, get operation here. 101 00:07:24,190 --> 00:07:26,140 So we will also use the insert here. 102 00:07:26,140 --> 00:07:35,560 So void insert hit value value or under case value here. 103 00:07:38,220 --> 00:07:40,680 Civil and void insert. 104 00:07:40,710 --> 00:07:42,720 Hail, insert. 105 00:07:43,500 --> 00:07:46,620 Hail or insert. 106 00:07:47,850 --> 00:07:50,400 Hail to Val. 107 00:07:51,450 --> 00:08:00,300 And also we will just need and as you can see, we have the link, the constructor we have here, we 108 00:08:00,300 --> 00:08:05,250 have get method insert hit we have here. 109 00:08:06,450 --> 00:08:07,560 Insert hit. 110 00:08:07,560 --> 00:08:09,000 Insert tail. 111 00:08:11,850 --> 00:08:12,420 Here. 112 00:08:12,420 --> 00:08:14,460 And let's write our application now. 113 00:08:15,240 --> 00:08:18,000 Insert tail and we will also use the remove here. 114 00:08:18,000 --> 00:08:20,100 So that's why we need to remove. 115 00:08:20,100 --> 00:08:23,820 Remove And for remove we get an a parameter index. 116 00:08:23,820 --> 00:08:26,400 So we will remove according to the index here. 117 00:08:26,430 --> 00:08:28,020 Integer index. 118 00:08:29,110 --> 00:08:30,250 And we will. 119 00:08:30,280 --> 00:08:32,680 So these are the removal operations here. 120 00:08:32,930 --> 00:08:34,150 Uh, remove here. 121 00:08:37,160 --> 00:08:39,920 And insert tail insert hit. 122 00:08:40,100 --> 00:08:42,410 So actually, let's make this comment here. 123 00:08:42,410 --> 00:08:45,350 So these are the insert operations. 124 00:08:45,380 --> 00:08:46,690 Operations. 125 00:08:46,700 --> 00:08:49,220 So insert hit, insert tail. 126 00:08:49,700 --> 00:08:52,520 Just and lastly, just a regular insert here. 127 00:08:52,520 --> 00:08:53,180 So. 128 00:08:53,270 --> 00:08:57,290 Insert and insert here. 129 00:08:57,320 --> 00:08:59,750 It's going to be get index and value. 130 00:09:00,170 --> 00:09:04,810 So integer index and value here. 131 00:09:04,820 --> 00:09:12,500 So after that, this is the index operation operators here and now this is the remove operations operations. 132 00:09:12,860 --> 00:09:18,860 After that, we firstly, we're going to create the void, remove, hit, remove. 133 00:09:19,680 --> 00:09:23,970 He'd also void, void. 134 00:09:24,060 --> 00:09:25,710 Remove tail. 135 00:09:28,050 --> 00:09:30,450 And, uh, that's it with the removal operations. 136 00:09:30,450 --> 00:09:32,820 So we have insert. 137 00:09:34,690 --> 00:09:41,410 Insert tail, insert head and remove tail, remove heat and remove here. 138 00:09:41,410 --> 00:09:44,680 So lastly, we need to declare our. 139 00:09:45,730 --> 00:09:48,460 Um, our search here. 140 00:09:49,090 --> 00:09:51,640 But, uh, before that. 141 00:09:52,660 --> 00:09:56,000 Yeah, let's actually create our search here. 142 00:09:56,020 --> 00:10:00,550 So this is search operation operations. 143 00:10:00,550 --> 00:10:01,090 The searches. 144 00:10:01,090 --> 00:10:03,030 As you can see, this is just a one method. 145 00:10:03,040 --> 00:10:08,050 So integer value, we will get search inside the search. 146 00:10:08,050 --> 00:10:12,010 We're going to get the one parameter that we want to search for here. 147 00:10:12,310 --> 00:10:17,290 And after that, we will use the additional parameters which is here. 148 00:10:17,290 --> 00:10:19,030 The search is also done. 149 00:10:19,030 --> 00:10:22,120 So what we did in the previous lecture, remember hit. 150 00:10:22,510 --> 00:10:27,880 Yes, we did count and print list method in previous lecture here. 151 00:10:27,880 --> 00:10:33,100 So we need to write our count count. 152 00:10:34,330 --> 00:10:35,290 And. 153 00:10:36,220 --> 00:10:40,330 Uh, was also what we need to write is print list. 154 00:10:40,330 --> 00:10:41,530 So print. 155 00:10:44,610 --> 00:10:47,940 List in parentheses we're going to use for method here. 156 00:10:48,090 --> 00:10:49,440 So now. 157 00:10:51,760 --> 00:10:53,560 These are the additional operators. 158 00:10:53,590 --> 00:10:54,610 Operations. 159 00:10:54,900 --> 00:10:55,900 Additional. 160 00:10:57,610 --> 00:11:03,770 At the channel operations or additional operations, which is the. 161 00:11:04,070 --> 00:11:07,100 This is the first count integer count here. 162 00:11:08,660 --> 00:11:13,940 And integer or, uh, this, this actually printing will not return anything. 163 00:11:13,940 --> 00:11:16,460 So we will define it as a void. 164 00:11:17,630 --> 00:11:19,910 Void print list. 165 00:11:21,790 --> 00:11:22,330 Here. 166 00:11:23,580 --> 00:11:26,460 So as you can see in this code, this is the declaration code. 167 00:11:26,670 --> 00:11:33,660 We have the count operation, which has the same functionality as the list in the previous lectures, 168 00:11:33,660 --> 00:11:38,740 which is used to inform us about the number of items in the linked list class. 169 00:11:38,760 --> 00:11:48,540 So there are also the print list operation to make it easier to print the content in the linked list 170 00:11:48,540 --> 00:11:49,410 class.