Hello.
My name is Stephan.
Welcome to another lecture of our course.
As you remember in previous lecture, we created our get and insert methods.
So now in this lecture, we are going to create our, uh, the search of search and remove methods.
So let's get started.
So here in Main.cpp.
So this is our insert get.
And now we're going to create search method.
So the search method will also iterate each items list until it finds the matched value.
So the return value of this method will be index of list and it will return the minus one if no result
is found.
So the implementation let's actually come to implementation part of our search method.
So now we're going to create the integer.
Integer list search here.
After that, we're going to loop through.
The array elements and we will return the array index if value is found.
So firstly for loop.
For loop integer is assigned integer to zero.
While our integer or while our a is less than my count, then increment E by one.
After that.
If our if our my items my items index is equals.
Duval.
Equals to vol.
Then return.
Re.
Turn here.
So this code here actually lets.
Striped is caught here.
So my items e.
Equals wow or yeah.
So my items here, here.
So this E.
Here is iterator.
So in this case our if my item.
So for example, my item items consists of two oops.
Not like this.
Yeah.
For example, my items consist of uh, here.
Two three, seven, 1299, 88, uh, 45 and etcetera.
So if our searched value is.
While, for example, if our search value is, uh.
Oops.
Why is that like that?
Yeah.
If our searched value is, for example, seven if the E here will iterate through to here.
So.
The two is going to be our seventh item here.
So it will find our element and we'll return the E here.
So let's actually write our LS here, so ls actually, we don't need ls here.
We just.
If this method is not executed, then it means we couldn't find our item and we will return.
Return minus one.
That's it.
As you can guess, the complexity of method of this method will be the zero and n multiply by n, so
for the average and worst case scenarios.
So it will for the average and worst scenarios and it will iterate through all these elements.
However, in the best case it can be 001.
So it is the best case.
Best.
But this is the, uh.
This is the average.
Average.
Or worst case.
This is average or best case this.
So, by the way, why this If you're asking why this is the best case here or one here, the or one,
it can be found if the VAL is found at the first position position.
So this means this in this case, it will be best case for us.
So if we are searching for seven and our element of seven in the first item, so first index of R,
so it the index is zero, then our this means we are on the best case scenario here.
So let's come to actually we also related here.
So we developed our get method insert method search method.
We just need to develop the remove method here so we will not just need to develop the remove method
here.
So let's get started.
So in this remove method, obviously as the name implies, the we will remove an item from list ADT
here.
So the removal method will iterate all list elements and then assign a new array to hold new list element.
So it will skip the select index to the removed item.
So the implementation here, let's actually make the implementation part.
So the search insert, get insert search here.
After the search, we're going to write our remove method here, void list remove here.
We're going to get the index here.
Integer.
Integer index index here.
We get an error here.
Why is that?
Because remove doesn't return anything, so remove is void.
We Yes.
Remove is void.
Each member must be definition.
Yes.
Hat In this case, we're going to index here.
So now we have no errors here.
Any n uh, so firstly.
We will check if the index is out of bounds.
So in this case, index, while if our index is less than zero or index is greater than our my count,
then it will return and do nothing.
After that, we will copy the current array as we did in the insert method.
So we will copy an old array integer old array here my items.
After that we will decrease the array length, so my count decrease array length and we will initialize
a new array.
My items equals new integer and my count.
So after that we will need to fill the new array and remove the selected index.
In order to do that, we will use the for loop.
So for integer for we will create the integer e and integer e and g here, integer e assigned integer
e to zero.
Also g to zero here.
While he is less than my count then.
Increment e by one and increment g by one.
And here.
So.
G equals to zero.
And while E is less than my count, then increment E by one increment G by one.
Here.
Oops.
Yeah.
Increment g by one here.
Now we also need the if statement here.
If index is g, then we will increment g by one.
And after that, my items or my items, my items, the index after that all array.
And here and we will also after that outside the for loop, we specify specifically outside the for
loop because we don't want to delete the array on each loop here.
So that would that would be pointless.
So delete.
Year old array.
So similar to the insert method.
The complexity of the remove method is O or zero.
Yeah.
Or zero here.
And.
So this is the complex of the zero remove method, even if the user removes the first position.