To find out the position of the selected value.
We need to traverse the list elements.
So once the selected value is matched with the value of the current position, the method just needs
to return its current position index.
So the implementation of the search operation here, we're going to develop our search operation here.
So we are developed the insert, hit the insert tail and insert and get here.
So now we're going to develop our search operation.
So my name is Stephan.
Welcome to another lecture of our Cplusplus course.
And let's get started.
Now we're going to develop our search operation.
Oops.
Not like this.
Here.
Redo here.
Yes, redo and here.
Let's get our delete this.
And after that we're going to develop our search operation.
So under the insert here, we're going to first we will create our template template type name, type,
name T, and after that, here we will.
So this search will return integer type.
So index of our node here.
So now integer linked list T here.
And this is going to be search here, which is going to take t val here.
And as you can see, Android studio is just automatically write it code for us and here.
So firstly, create the condition.
So if our linked list is empty, just return not found here.
So in this case, not found here, the minus one here.
In this case, it's going to be the not.
Font.
Here.
So let's actually make it if my count is equal to zero.
My I.
If I have zero items in list, then return minus one.
So if there is a no items, how can I search it right here?
And after that we will need to count the index.
So we will create an index here.
So integer index, in this case, it's going to firstly start with the zero and after that we're going
to traverse from the head node.
So node T and node hit here and we will create a while loop here.
To traverse until the selected value is matched with the value of the current position.
Here it will look like this.
Here, for example.
This is one.
Let's actually.
Yeah.
For example, this is one five.
Five.
Six, four.
Three nine.
Or, for example, 20.
2029.
Or and to and here, for example, if we are searching for the or for if we are searching for for here
searching.
Search.
For here.
So this while loop will continue here.
If one is is one is equals to four, you know, then we'll continue to five, six, four.
And here we found the for the loop will break here.
Here, so the loop will not continue.
And not look at here since we found the four here.
So let's get started by writing our while loop now.
So.
While our not.
Here.
Node value value is not equals to our this value here.
So is not equals to our value that we're going to get with the we're going to get from the parameter
of our search then here, then until here.
So until this value is not equals to.
Value.
Then keep looping here.
So.
Well, then keep looping.
So we will increase the index by one.
So we will.
So we will look at other next indexes here.
And after that we're going to note here.
Node Node next.
And here.
If our node is null, if our node is null here, then it will return return minus one again.
So if our count is we have nothing in our list, then it will return minus one which is not found.
And if our node is null, it will also return minus one here.
And after that we will just outside the while loop here, we will just return the index.
Return the index here.
So that's it.
So again, since we need to traverse list element, the complexity of this operation here will be here.
The complexity of this operation is going to be zero.
And multiply by n here.
Science and is our number of items that we're going to search.
But however the selected value here, for example, let's create another example again here, for example.
The two of us here, for example.
Two, five.
32.
15.
80 here.
Three of three and nine.
So, for example, for example, if we are searching for two, then we will first find this.
So that is going to be our best case scenarios because it's going to be zero one here.
But in the worst case scenario, for example, we have one, two, three, four, five, six, seven
elements and here we are, select this here, oops, Here, let's select different color.
So we will check this.
Yeah, it's not equal to for example, if we are searching for nine, it's not nine naught nine naught
nine naught nine here and not nine.
And as you can see here, we finally found nine, which is it's going to be our worst case.
So worst case.
This is our worst case scenario in our application.