1 00:00:00,470 --> 00:00:01,640 Hello, my name is Stephanie. 2 00:00:01,640 --> 00:00:06,500 And in this lecture of the course you will learn about the how to fetch an item in the list. 3 00:00:06,500 --> 00:00:08,900 So let's implement the get method here. 4 00:00:08,900 --> 00:00:17,900 So as you remember, we've written that get method to get an item from the index that you defined here 5 00:00:17,900 --> 00:00:21,530 and as you can see here, gets an item from an index. 6 00:00:21,740 --> 00:00:23,720 So we're going to do it now. 7 00:00:23,720 --> 00:00:33,980 So in order to use the our header file in our main class, we need to implement our the listed here. 8 00:00:33,980 --> 00:00:36,020 So as you can see, this is a default class. 9 00:00:36,020 --> 00:00:45,350 We will include the include the list dot h header file and here above the main function we will create 10 00:00:45,350 --> 00:00:47,240 an integer list. 11 00:00:47,360 --> 00:00:49,940 Get here integer index. 12 00:00:49,940 --> 00:00:52,310 As you can see it autocompleted itself. 13 00:00:52,310 --> 00:00:54,410 And here we will get. 14 00:00:54,560 --> 00:01:01,320 Firstly, as you remember we in previous lecture we need to check if the index is out of bounds. 15 00:01:01,320 --> 00:01:11,910 So if our index is less than zero or if our index is greater than my count, then we will return minus 16 00:01:11,910 --> 00:01:12,360 one. 17 00:01:12,360 --> 00:01:22,080 So we have an error and we are out of bounds here, but else we will return return the My items index. 18 00:01:22,080 --> 00:01:27,060 So in this case we're going to get this index and put it in here. 19 00:01:27,420 --> 00:01:31,350 So here my items and index. 20 00:01:32,340 --> 00:01:40,050 So as you can see here in this code, the complexity of the get method is the complexity here. 21 00:01:41,100 --> 00:01:50,120 The complex, complex complexity is equals zero one here. 22 00:01:50,160 --> 00:01:58,230 So since it doesn't depend on the number of the list elements, so we will also create an item into 23 00:01:58,230 --> 00:02:00,480 the list, an insert method. 24 00:02:00,510 --> 00:02:06,930 So here, as we said, the complex of the get here equals to zero one here. 25 00:02:07,020 --> 00:02:11,070 Now we're going to create this here. 26 00:02:13,230 --> 00:02:15,050 Actually, let's delete that now. 27 00:02:15,060 --> 00:02:18,540 And now we will return to our state here. 28 00:02:18,540 --> 00:02:23,430 And as you can see in the list is empty since we are not creating in it so we can close it. 29 00:02:23,430 --> 00:02:27,960 And now and as you can see, we implemented get method. 30 00:02:27,960 --> 00:02:30,780 So this implemented here. 31 00:02:31,890 --> 00:02:36,720 Implemented and we need to implement the create the insert method here. 32 00:02:37,890 --> 00:02:40,260 So let's create our insert method here. 33 00:02:40,440 --> 00:02:42,660 Now, here. 34 00:02:44,770 --> 00:02:48,340 Now we will go here and write list. 35 00:02:48,610 --> 00:02:54,220 And actually after that we need to iterate each item of the old my items variable and then assign them 36 00:02:54,220 --> 00:02:56,290 to the my new items variable. 37 00:02:56,290 --> 00:03:04,300 So we also need to ensure that we put the new item stated by the index variable passed by the user. 38 00:03:04,330 --> 00:03:05,950 The implementation is like that. 39 00:03:05,950 --> 00:03:12,460 So firstly we are going to void list insert and as you can see our insert function is actually void 40 00:03:12,460 --> 00:03:12,670 here. 41 00:03:12,670 --> 00:03:15,580 So it doesn't return anything and it doesn't need to return anything here. 42 00:03:15,760 --> 00:03:21,610 So firstly we will check if the index is out of bounds like we did in the get method. 43 00:03:21,610 --> 00:03:26,950 So if our variable is out of bounds then how can we reach it? 44 00:03:26,950 --> 00:03:27,430 Right. 45 00:03:27,880 --> 00:03:30,040 We should give an get an error here. 46 00:03:30,040 --> 00:03:40,600 So if here our index is less than zero or index is greater than my count, then just a return. 47 00:03:40,600 --> 00:03:41,170 Nothing. 48 00:03:41,170 --> 00:03:46,040 So just return and here we will copy the current array here. 49 00:03:46,040 --> 00:03:51,050 So integer when you create a new array or old array here. 50 00:03:52,140 --> 00:03:53,730 And my items. 51 00:03:53,730 --> 00:04:00,420 And also we will increase the array length by this, my count plus plus here we will initialize a new 52 00:04:00,420 --> 00:04:01,230 array. 53 00:04:01,530 --> 00:04:07,650 My items equals new integer array and my count. 54 00:04:08,160 --> 00:04:13,260 So after that we're going to fill the new array with the inserted data. 55 00:04:13,260 --> 00:04:16,710 So we're going to use the iterate iterator. 56 00:04:16,710 --> 00:04:19,110 So we're going to use full for loop. 57 00:04:19,110 --> 00:04:25,920 So for integer here, zero zero, we will define two variables in it. 58 00:04:26,370 --> 00:04:31,020 And while our E is less than my count then. 59 00:04:32,050 --> 00:04:33,460 Increment E by one. 60 00:04:33,460 --> 00:04:34,210 Plus plus E. 61 00:04:35,390 --> 00:04:40,460 And here we also need to create a if else statement in this. 62 00:04:40,460 --> 00:04:42,800 So if our index. 63 00:04:43,830 --> 00:04:56,760 If our index is if our index is equal to E, then my items of my items index should be while here. 64 00:04:58,890 --> 00:05:00,090 And here. 65 00:05:03,580 --> 00:05:05,140 Let's create a function now. 66 00:05:05,350 --> 00:05:07,030 Else statement now. 67 00:05:07,030 --> 00:05:08,350 So else. 68 00:05:08,860 --> 00:05:15,280 If else happens, then my items here is going to be all array. 69 00:05:15,700 --> 00:05:19,600 All array and it's going to be get the G here. 70 00:05:20,930 --> 00:05:21,770 So. 71 00:05:22,990 --> 00:05:23,920 Uh, here. 72 00:05:25,290 --> 00:05:26,520 Old array. 73 00:05:26,520 --> 00:05:28,080 And it's going to be. 74 00:05:30,040 --> 00:05:32,230 Gear and we will increment G by one. 75 00:05:34,230 --> 00:05:38,790 After that, we also need to remove the copied array here. 76 00:05:38,790 --> 00:05:39,660 So. 77 00:05:41,720 --> 00:05:44,970 Separated from the fourth statement here. 78 00:05:44,990 --> 00:05:51,410 Between this, we will write a new code here which will delete all the arrays. 79 00:05:51,440 --> 00:05:52,490 The old arrays here. 80 00:05:52,520 --> 00:05:53,830 Not all the arrays here. 81 00:05:53,840 --> 00:05:56,510 So delete here. 82 00:05:56,540 --> 00:05:59,510 Delete old array. 83 00:06:00,320 --> 00:06:04,130 So as you can see here, we need counter variables. 84 00:06:04,220 --> 00:06:09,080 The E here, the E and G. 85 00:06:11,570 --> 00:06:16,720 Uh, we need this E and G to assign an old array. 86 00:06:17,470 --> 00:06:24,850 To the new array size V, it will iterate all elements of list items and the number of items matters. 87 00:06:24,850 --> 00:06:28,900 So the complexity will be the zero ops. 88 00:06:28,930 --> 00:06:31,570 Okay, so the complexity will be zero. 89 00:06:33,240 --> 00:06:34,080 And here. 90 00:06:36,220 --> 00:06:37,690 Where the n here. 91 00:06:37,720 --> 00:06:41,320 This n the this n here. 92 00:06:44,410 --> 00:06:45,910 In the number. 93 00:06:46,630 --> 00:06:51,130 Actually, this n is the number of the list elements. 94 00:06:53,400 --> 00:06:53,940 Actually. 95 00:06:53,940 --> 00:06:59,340 Now, we have also created our list here. 96 00:06:59,430 --> 00:07:01,740 So now let's delete this. 97 00:07:01,740 --> 00:07:05,220 So we write it, our get insert. 98 00:07:05,220 --> 00:07:10,770 And what we have to write next is the search method. 99 00:07:11,100 --> 00:07:16,950 So we in next lecture, we will create our search method. 100 00:07:16,950 --> 00:07:18,210 So I'm waiting in next lecture.