WEBVTT

00:00.500 --> 00:00.800
Hello.

00:00.800 --> 00:01.940
My name is Stephan.

00:02.180 --> 00:04.480
Welcome to another lecture of our course.

00:04.490 --> 00:10.310
As you remember in previous lecture, we created our get and insert methods.

00:10.310 --> 00:20.780
So now in this lecture, we are going to create our, uh, the search of search and remove methods.

00:20.780 --> 00:22.280
So let's get started.

00:23.210 --> 00:24.890
So here in Main.cpp.

00:24.890 --> 00:28.310
So this is our insert get.

00:28.310 --> 00:31.070
And now we're going to create search method.

00:31.250 --> 00:38.690
So the search method will also iterate each items list until it finds the matched value.

00:38.960 --> 00:47.300
So the return value of this method will be index of list and it will return the minus one if no result

00:47.300 --> 00:47.780
is found.

00:47.780 --> 00:55.340
So the implementation let's actually come to implementation part of our search method.

00:56.470 --> 01:00.340
So now we're going to create the integer.

01:01.240 --> 01:04.750
Integer list search here.

01:05.500 --> 01:07.540
After that, we're going to loop through.

01:07.570 --> 01:13.300
The array elements and we will return the array index if value is found.

01:13.570 --> 01:16.090
So firstly for loop.

01:16.270 --> 01:20.980
For loop integer is assigned integer to zero.

01:21.040 --> 01:28.750
While our integer or while our a is less than my count, then increment E by one.

01:30.030 --> 01:30.960
After that.

01:31.880 --> 01:39.610
If our if our my items my items index is equals.

01:41.040 --> 01:41.730
Duval.

01:43.910 --> 01:45.080
Equals to vol.

01:46.220 --> 01:48.350
Then return.

01:49.380 --> 01:50.040
Re.

01:51.740 --> 01:52.760
Turn here.

01:52.880 --> 01:56.420
So this code here actually lets.

01:57.760 --> 01:59.230
Striped is caught here.

01:59.230 --> 02:02.680
So my items e.

02:04.230 --> 02:06.630
Equals wow or yeah.

02:06.960 --> 02:08.940
So my items here, here.

02:08.940 --> 02:10.470
So this E.

02:12.780 --> 02:14.130
Here is iterator.

02:14.130 --> 02:16.440
So in this case our if my item.

02:16.440 --> 02:20.550
So for example, my item items consists of two oops.

02:20.730 --> 02:21.450
Not like this.

02:21.450 --> 02:21.900
Yeah.

02:21.900 --> 02:25.620
For example, my items consist of uh, here.

02:26.460 --> 02:34.140
Two three, seven, 1299, 88, uh, 45 and etcetera.

02:34.650 --> 02:39.360
So if our searched value is.

02:40.200 --> 02:43.740
While, for example, if our search value is, uh.

02:43.950 --> 02:44.330
Oops.

02:44.370 --> 02:46.110
Why is that like that?

02:46.710 --> 02:47.400
Yeah.

02:49.910 --> 02:59.960
If our searched value is, for example, seven if the E here will iterate through to here.

02:59.960 --> 03:00.680
So.

03:01.490 --> 03:05.270
The two is going to be our seventh item here.

03:05.270 --> 03:11.810
So it will find our element and we'll return the E here.

03:12.320 --> 03:17.840
So let's actually write our LS here, so ls actually, we don't need ls here.

03:17.840 --> 03:18.560
We just.

03:18.560 --> 03:24.740
If this method is not executed, then it means we couldn't find our item and we will return.

03:25.070 --> 03:26.810
Return minus one.

03:26.990 --> 03:27.810
That's it.

03:27.830 --> 03:36.770
As you can guess, the complexity of method of this method will be the zero and n multiply by n, so

03:36.770 --> 03:39.260
for the average and worst case scenarios.

03:39.590 --> 03:45.950
So it will for the average and worst scenarios and it will iterate through all these elements.

03:45.950 --> 03:52.820
However, in the best case it can be 001.

03:54.160 --> 03:57.040
So it is the best case.

03:58.060 --> 03:58.840
Best.

04:00.700 --> 04:03.510
But this is the, uh.

04:03.580 --> 04:06.070
This is the average.

04:07.060 --> 04:08.020
Average.

04:09.330 --> 04:11.070
Or worst case.

04:13.340 --> 04:15.010
This is average or best case this.

04:15.170 --> 04:23.360
So, by the way, why this If you're asking why this is the best case here or one here, the or one,

04:23.360 --> 04:28.040
it can be found if the VAL is found at the first position position.

04:28.040 --> 04:33.260
So this means this in this case, it will be best case for us.

04:33.260 --> 04:41.780
So if we are searching for seven and our element of seven in the first item, so first index of R,

04:41.780 --> 04:49.910
so it the index is zero, then our this means we are on the best case scenario here.

04:49.970 --> 04:53.590
So let's come to actually we also related here.

04:53.600 --> 04:59.270
So we developed our get method insert method search method.

04:59.270 --> 05:06.110
We just need to develop the remove method here so we will not just need to develop the remove method

05:06.110 --> 05:06.590
here.

05:07.100 --> 05:08.450
So let's get started.

05:08.450 --> 05:17.110
So in this remove method, obviously as the name implies, the we will remove an item from list ADT

05:17.210 --> 05:17.750
here.

05:17.900 --> 05:27.920
So the removal method will iterate all list elements and then assign a new array to hold new list element.

05:27.920 --> 05:31.850
So it will skip the select index to the removed item.

05:31.850 --> 05:35.780
So the implementation here, let's actually make the implementation part.

05:35.780 --> 05:39.800
So the search insert, get insert search here.

05:39.800 --> 05:47.210
After the search, we're going to write our remove method here, void list remove here.

05:47.210 --> 05:48.920
We're going to get the index here.

05:48.920 --> 05:49.760
Integer.

05:51.020 --> 05:54.410
Integer index index here.

05:54.950 --> 05:55.780
We get an error here.

05:55.790 --> 05:56.930
Why is that?

05:56.930 --> 06:00.050
Because remove doesn't return anything, so remove is void.

06:00.050 --> 06:01.640
We Yes.

06:01.640 --> 06:02.720
Remove is void.

06:05.510 --> 06:08.060
Each member must be definition.

06:08.060 --> 06:09.140
Yes.

06:10.010 --> 06:12.350
Hat In this case, we're going to index here.

06:12.350 --> 06:16.490
So now we have no errors here.

06:16.490 --> 06:18.710
Any n uh, so firstly.

06:19.620 --> 06:22.950
We will check if the index is out of bounds.

06:22.980 --> 06:33.780
So in this case, index, while if our index is less than zero or index is greater than our my count,

06:33.810 --> 06:36.360
then it will return and do nothing.

06:37.050 --> 06:43.590
After that, we will copy the current array as we did in the insert method.

06:43.590 --> 06:51.360
So we will copy an old array integer old array here my items.

06:51.390 --> 06:59.370
After that we will decrease the array length, so my count decrease array length and we will initialize

06:59.370 --> 07:00.000
a new array.

07:00.030 --> 07:04.890
My items equals new integer and my count.

07:05.460 --> 07:12.630
So after that we will need to fill the new array and remove the selected index.

07:12.630 --> 07:15.350
In order to do that, we will use the for loop.

07:15.360 --> 07:26.250
So for integer for we will create the integer e and integer e and g here, integer e assigned integer

07:26.250 --> 07:27.360
e to zero.

07:27.480 --> 07:31.050
Also g to zero here.

07:31.830 --> 07:36.120
While he is less than my count then.

07:37.990 --> 07:41.560
Increment e by one and increment g by one.

07:41.560 --> 07:42.360
And here.

07:42.370 --> 07:43.180
So.

07:44.870 --> 07:46.910
G equals to zero.

07:46.910 --> 07:55.460
And while E is less than my count, then increment E by one increment G by one.

07:57.350 --> 07:58.100
Here.

07:58.610 --> 07:59.150
Oops.

07:59.570 --> 08:00.050
Yeah.

08:00.080 --> 08:04.640
Increment g by one here.

08:04.970 --> 08:07.520
Now we also need the if statement here.

08:07.520 --> 08:12.350
If index is g, then we will increment g by one.

08:13.650 --> 08:23.750
And after that, my items or my items, my items, the index after that all array.

08:23.760 --> 08:33.390
And here and we will also after that outside the for loop, we specify specifically outside the for

08:33.390 --> 08:36.480
loop because we don't want to delete the array on each loop here.

08:36.480 --> 08:39.120
So that would that would be pointless.

08:39.120 --> 08:40.500
So delete.

08:41.880 --> 08:44.620
Year old array.

08:45.540 --> 08:47.580
So similar to the insert method.

08:47.580 --> 08:53.430
The complexity of the remove method is O or zero.

08:53.850 --> 08:54.190
Yeah.

08:54.360 --> 08:55.620
Or zero here.

08:56.450 --> 08:56.840
And.

08:59.230 --> 09:07.330
So this is the complex of the zero remove method, even if the user removes the first position.
