WEBVTT

00:00.470 --> 00:01.640
Hello, my name is Stephanie.

00:01.640 --> 00:06.500
And in this lecture of the course you will learn about the how to fetch an item in the list.

00:06.500 --> 00:08.900
So let's implement the get method here.

00:08.900 --> 00:17.900
So as you remember, we've written that get method to get an item from the index that you defined here

00:17.900 --> 00:21.530
and as you can see here, gets an item from an index.

00:21.740 --> 00:23.720
So we're going to do it now.

00:23.720 --> 00:33.980
So in order to use the our header file in our main class, we need to implement our the listed here.

00:33.980 --> 00:36.020
So as you can see, this is a default class.

00:36.020 --> 00:45.350
We will include the include the list dot h header file and here above the main function we will create

00:45.350 --> 00:47.240
an integer list.

00:47.360 --> 00:49.940
Get here integer index.

00:49.940 --> 00:52.310
As you can see it autocompleted itself.

00:52.310 --> 00:54.410
And here we will get.

00:54.560 --> 01:01.320
Firstly, as you remember we in previous lecture we need to check if the index is out of bounds.

01:01.320 --> 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

01:11.910 --> 01:12.360
one.

01:12.360 --> 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.

01:22.080 --> 01:27.060
So in this case we're going to get this index and put it in here.

01:27.420 --> 01:31.350
So here my items and index.

01:32.340 --> 01:40.050
So as you can see here in this code, the complexity of the get method is the complexity here.

01:41.100 --> 01:50.120
The complex, complex complexity is equals zero one here.

01:50.160 --> 01:58.230
So since it doesn't depend on the number of the list elements, so we will also create an item into

01:58.230 --> 02:00.480
the list, an insert method.

02:00.510 --> 02:06.930
So here, as we said, the complex of the get here equals to zero one here.

02:07.020 --> 02:11.070
Now we're going to create this here.

02:13.230 --> 02:15.050
Actually, let's delete that now.

02:15.060 --> 02:18.540
And now we will return to our state here.

02:18.540 --> 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.

02:23.430 --> 02:27.960
And now and as you can see, we implemented get method.

02:27.960 --> 02:30.780
So this implemented here.

02:31.890 --> 02:36.720
Implemented and we need to implement the create the insert method here.

02:37.890 --> 02:40.260
So let's create our insert method here.

02:40.440 --> 02:42.660
Now, here.

02:44.770 --> 02:48.340
Now we will go here and write list.

02:48.610 --> 02:54.220
And actually after that we need to iterate each item of the old my items variable and then assign them

02:54.220 --> 02:56.290
to the my new items variable.

02:56.290 --> 03:04.300
So we also need to ensure that we put the new item stated by the index variable passed by the user.

03:04.330 --> 03:05.950
The implementation is like that.

03:05.950 --> 03:12.460
So firstly we are going to void list insert and as you can see our insert function is actually void

03:12.460 --> 03:12.670
here.

03:12.670 --> 03:15.580
So it doesn't return anything and it doesn't need to return anything here.

03:15.760 --> 03:21.610
So firstly we will check if the index is out of bounds like we did in the get method.

03:21.610 --> 03:26.950
So if our variable is out of bounds then how can we reach it?

03:26.950 --> 03:27.430
Right.

03:27.880 --> 03:30.040
We should give an get an error here.

03:30.040 --> 03:40.600
So if here our index is less than zero or index is greater than my count, then just a return.

03:40.600 --> 03:41.170
Nothing.

03:41.170 --> 03:46.040
So just return and here we will copy the current array here.

03:46.040 --> 03:51.050
So integer when you create a new array or old array here.

03:52.140 --> 03:53.730
And my items.

03:53.730 --> 04:00.420
And also we will increase the array length by this, my count plus plus here we will initialize a new

04:00.420 --> 04:01.230
array.

04:01.530 --> 04:07.650
My items equals new integer array and my count.

04:08.160 --> 04:13.260
So after that we're going to fill the new array with the inserted data.

04:13.260 --> 04:16.710
So we're going to use the iterate iterator.

04:16.710 --> 04:19.110
So we're going to use full for loop.

04:19.110 --> 04:25.920
So for integer here, zero zero, we will define two variables in it.

04:26.370 --> 04:31.020
And while our E is less than my count then.

04:32.050 --> 04:33.460
Increment E by one.

04:33.460 --> 04:34.210
Plus plus E.

04:35.390 --> 04:40.460
And here we also need to create a if else statement in this.

04:40.460 --> 04:42.800
So if our index.

04:43.830 --> 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.

04:58.890 --> 05:00.090
And here.

05:03.580 --> 05:05.140
Let's create a function now.

05:05.350 --> 05:07.030
Else statement now.

05:07.030 --> 05:08.350
So else.

05:08.860 --> 05:15.280
If else happens, then my items here is going to be all array.

05:15.700 --> 05:19.600
All array and it's going to be get the G here.

05:20.930 --> 05:21.770
So.

05:22.990 --> 05:23.920
Uh, here.

05:25.290 --> 05:26.520
Old array.

05:26.520 --> 05:28.080
And it's going to be.

05:30.040 --> 05:32.230
Gear and we will increment G by one.

05:34.230 --> 05:38.790
After that, we also need to remove the copied array here.

05:38.790 --> 05:39.660
So.

05:41.720 --> 05:44.970
Separated from the fourth statement here.

05:44.990 --> 05:51.410
Between this, we will write a new code here which will delete all the arrays.

05:51.440 --> 05:52.490
The old arrays here.

05:52.520 --> 05:53.830
Not all the arrays here.

05:53.840 --> 05:56.510
So delete here.

05:56.540 --> 05:59.510
Delete old array.

06:00.320 --> 06:04.130
So as you can see here, we need counter variables.

06:04.220 --> 06:09.080
The E here, the E and G.

06:11.570 --> 06:16.720
Uh, we need this E and G to assign an old array.

06:17.470 --> 06:24.850
To the new array size V, it will iterate all elements of list items and the number of items matters.

06:24.850 --> 06:28.900
So the complexity will be the zero ops.

06:28.930 --> 06:31.570
Okay, so the complexity will be zero.

06:33.240 --> 06:34.080
And here.

06:36.220 --> 06:37.690
Where the n here.

06:37.720 --> 06:41.320
This n the this n here.

06:44.410 --> 06:45.910
In the number.

06:46.630 --> 06:51.130
Actually, this n is the number of the list elements.

06:53.400 --> 06:53.940
Actually.

06:53.940 --> 06:59.340
Now, we have also created our list here.

06:59.430 --> 07:01.740
So now let's delete this.

07:01.740 --> 07:05.220
So we write it, our get insert.

07:05.220 --> 07:10.770
And what we have to write next is the search method.

07:11.100 --> 07:16.950
So we in next lecture, we will create our search method.

07:16.950 --> 07:18.210
So I'm waiting in next lecture.
