WEBVTT

00:02.030 --> 00:04.760
To find out the position of the selected value.

00:04.790 --> 00:07.070
We need to traverse the list elements.

00:07.070 --> 00:13.670
So once the selected value is matched with the value of the current position, the method just needs

00:13.670 --> 00:15.620
to return its current position index.

00:15.620 --> 00:23.480
So the implementation of the search operation here, we're going to develop our search operation here.

00:23.480 --> 00:31.490
So we are developed the insert, hit the insert tail and insert and get here.

00:31.490 --> 00:35.150
So now we're going to develop our search operation.

00:35.150 --> 00:36.920
So my name is Stephan.

00:37.160 --> 00:40.550
Welcome to another lecture of our Cplusplus course.

00:40.550 --> 00:42.680
And let's get started.

00:56.720 --> 01:00.720
Now we're going to develop our search operation.

01:00.740 --> 01:01.240
Oops.

01:01.370 --> 01:02.170
Not like this.

01:02.180 --> 01:02.810
Here.

01:03.080 --> 01:04.150
Redo here.

01:04.160 --> 01:08.390
Yes, redo and here.

01:11.000 --> 01:13.010
Let's get our delete this.

01:13.010 --> 01:16.280
And after that we're going to develop our search operation.

01:16.280 --> 01:26.930
So under the insert here, we're going to first we will create our template template type name, type,

01:26.930 --> 01:31.910
name T, and after that, here we will.

01:32.270 --> 01:35.450
So this search will return integer type.

01:35.450 --> 01:37.730
So index of our node here.

01:37.730 --> 01:41.570
So now integer linked list T here.

01:41.570 --> 01:46.280
And this is going to be search here, which is going to take t val here.

01:46.280 --> 01:53.420
And as you can see, Android studio is just automatically write it code for us and here.

01:55.210 --> 01:57.070
So firstly, create the condition.

01:57.070 --> 02:01.050
So if our linked list is empty, just return not found here.

02:01.060 --> 02:04.840
So in this case, not found here, the minus one here.

02:04.840 --> 02:08.650
In this case, it's going to be the not.

02:10.500 --> 02:11.040
Font.

02:14.460 --> 02:15.090
Here.

02:15.240 --> 02:23.220
So let's actually make it if my count is equal to zero.

02:23.820 --> 02:24.630
My I.

02:24.690 --> 02:30.240
If I have zero items in list, then return minus one.

02:30.240 --> 02:33.960
So if there is a no items, how can I search it right here?

02:34.590 --> 02:37.530
And after that we will need to count the index.

02:37.530 --> 02:39.000
So we will create an index here.

02:39.000 --> 02:44.010
So integer index, in this case, it's going to firstly start with the zero and after that we're going

02:44.010 --> 02:45.630
to traverse from the head node.

02:45.630 --> 02:54.690
So node T and node hit here and we will create a while loop here.

02:55.420 --> 03:02.420
To traverse until the selected value is matched with the value of the current position.

03:02.440 --> 03:04.720
Here it will look like this.

03:04.750 --> 03:05.470
Here, for example.

03:05.470 --> 03:06.130
This is one.

03:06.400 --> 03:07.030
Let's actually.

03:07.030 --> 03:07.390
Yeah.

03:07.420 --> 03:10.000
For example, this is one five.

03:11.200 --> 03:12.010
Five.

03:12.010 --> 03:14.620
Six, four.

03:15.850 --> 03:17.800
Three nine.

03:19.420 --> 03:21.490
Or, for example, 20.

03:23.300 --> 03:26.690
2029.

03:27.530 --> 03:37.520
Or and to and here, for example, if we are searching for the or for if we are searching for for here

03:37.790 --> 03:39.170
searching.

03:43.000 --> 03:43.990
Search.

03:44.980 --> 03:45.730
For here.

03:45.730 --> 03:48.130
So this while loop will continue here.

03:48.130 --> 03:56.200
If one is is one is equals to four, you know, then we'll continue to five, six, four.

03:56.200 --> 04:01.360
And here we found the for the loop will break here.

04:02.720 --> 04:06.590
Here, so the loop will not continue.

04:07.510 --> 04:11.260
And not look at here since we found the four here.

04:11.530 --> 04:15.910
So let's get started by writing our while loop now.

04:16.030 --> 04:17.020
So.

04:19.110 --> 04:22.170
While our not.

04:23.120 --> 04:23.980
Here.

04:24.170 --> 04:30.170
Node value value is not equals to our this value here.

04:30.170 --> 04:36.140
So is not equals to our value that we're going to get with the we're going to get from the parameter

04:36.140 --> 04:41.420
of our search then here, then until here.

04:41.420 --> 04:43.730
So until this value is not equals to.

04:45.080 --> 04:45.830
Value.

04:46.250 --> 04:48.080
Then keep looping here.

04:48.080 --> 04:48.410
So.

04:48.410 --> 04:50.270
Well, then keep looping.

04:50.270 --> 04:53.390
So we will increase the index by one.

04:53.390 --> 04:54.080
So we will.

04:54.080 --> 04:57.590
So we will look at other next indexes here.

04:57.590 --> 05:01.230
And after that we're going to note here.

05:01.280 --> 05:04.730
Node Node next.

05:05.270 --> 05:06.650
And here.

05:08.180 --> 05:17.600
If our node is null, if our node is null here, then it will return return minus one again.

05:17.600 --> 05:25.580
So if our count is we have nothing in our list, then it will return minus one which is not found.

05:25.580 --> 05:31.340
And if our node is null, it will also return minus one here.

05:35.630 --> 05:42.890
And after that we will just outside the while loop here, we will just return the index.

05:43.160 --> 05:45.740
Return the index here.

05:46.790 --> 05:47.930
So that's it.

05:48.080 --> 05:55.280
So again, since we need to traverse list element, the complexity of this operation here will be here.

05:55.280 --> 05:58.190
The complexity of this operation is going to be zero.

05:59.740 --> 06:02.530
And multiply by n here.

06:03.350 --> 06:06.590
Science and is our number of items that we're going to search.

06:06.590 --> 06:15.050
But however the selected value here, for example, let's create another example again here, for example.

06:16.200 --> 06:20.190
The two of us here, for example.

06:20.220 --> 06:22.110
Two, five.

06:23.120 --> 06:24.170
32.

06:25.340 --> 06:26.330
15.

06:28.840 --> 06:30.190
80 here.

06:31.900 --> 06:35.530
Three of three and nine.

06:35.560 --> 06:44.230
So, for example, for example, if we are searching for two, then we will first find this.

06:44.230 --> 06:50.800
So that is going to be our best case scenarios because it's going to be zero one here.

06:50.800 --> 06:57.610
But in the worst case scenario, for example, we have one, two, three, four, five, six, seven

06:57.610 --> 07:03.340
elements and here we are, select this here, oops, Here, let's select different color.

07:03.340 --> 07:04.420
So we will check this.

07:04.420 --> 07:10.900
Yeah, it's not equal to for example, if we are searching for nine, it's not nine naught nine naught

07:10.900 --> 07:12.940
nine naught nine here and not nine.

07:12.940 --> 07:19.300
And as you can see here, we finally found nine, which is it's going to be our worst case.

07:19.300 --> 07:22.030
So worst case.

07:23.620 --> 07:28.510
This is our worst case scenario in our application.
