Hello, my name is Stephanie.
And in this lecture of the course you will learn about the how to fetch an item in the list.
So let's implement the get method here.
So as you remember, we've written that get method to get an item from the index that you defined here
and as you can see here, gets an item from an index.
So we're going to do it now.
So in order to use the our header file in our main class, we need to implement our the listed here.
So as you can see, this is a default class.
We will include the include the list dot h header file and here above the main function we will create
an integer list.
Get here integer index.
As you can see it autocompleted itself.
And here we will get.
Firstly, as you remember we in previous lecture we need to check if the index is out of bounds.
So if our index is less than zero or if our index is greater than my count, then we will return minus
one.
So we have an error and we are out of bounds here, but else we will return return the My items index.
So in this case we're going to get this index and put it in here.
So here my items and index.
So as you can see here in this code, the complexity of the get method is the complexity here.
The complex, complex complexity is equals zero one here.
So since it doesn't depend on the number of the list elements, so we will also create an item into
the list, an insert method.
So here, as we said, the complex of the get here equals to zero one here.
Now we're going to create this here.
Actually, let's delete that now.
And now we will return to our state here.
And as you can see in the list is empty since we are not creating in it so we can close it.
And now and as you can see, we implemented get method.
So this implemented here.
Implemented and we need to implement the create the insert method here.
So let's create our insert method here.
Now, here.
Now we will go here and write list.
And actually after that we need to iterate each item of the old my items variable and then assign them
to the my new items variable.
So we also need to ensure that we put the new item stated by the index variable passed by the user.
The implementation is like that.
So firstly we are going to void list insert and as you can see our insert function is actually void
here.
So it doesn't return anything and it doesn't need to return anything here.
So firstly we will check if the index is out of bounds like we did in the get method.
So if our variable is out of bounds then how can we reach it?
Right.
We should give an get an error here.
So if here our index is less than zero or index is greater than my count, then just a return.
Nothing.
So just return and here we will copy the current array here.
So integer when you create a new array or old array here.
And my items.
And also we will increase the array length by this, my count plus plus here we will initialize a new
array.
My items equals new integer array and my count.
So after that we're going to fill the new array with the inserted data.
So we're going to use the iterate iterator.
So we're going to use full for loop.
So for integer here, zero zero, we will define two variables in it.
And while our E is less than my count then.
Increment E by one.
Plus plus E.
And here we also need to create a if else statement in this.
So if our index.
If our index is if our index is equal to E, then my items of my items index should be while here.
And here.
Let's create a function now.
Else statement now.
So else.
If else happens, then my items here is going to be all array.
All array and it's going to be get the G here.
So.
Uh, here.
Old array.
And it's going to be.
Gear and we will increment G by one.
After that, we also need to remove the copied array here.
So.
Separated from the fourth statement here.
Between this, we will write a new code here which will delete all the arrays.
The old arrays here.
Not all the arrays here.
So delete here.
Delete old array.
So as you can see here, we need counter variables.
The E here, the E and G.
Uh, we need this E and G to assign an old array.
To the new array size V, it will iterate all elements of list items and the number of items matters.
So the complexity will be the zero ops.
Okay, so the complexity will be zero.
And here.
Where the n here.
This n the this n here.
In the number.
Actually, this n is the number of the list elements.
Actually.
Now, we have also created our list here.
So now let's delete this.
So we write it, our get insert.
And what we have to write next is the search method.
So we in next lecture, we will create our search method.
So I'm waiting in next lecture.