Now let's consume our new list data type.
So we will initialize a new list and give some items to it.
So we will then insert several items again and find out how it works.
So and then we will remove an item that we previously searched for and then search for the item again
to ensure that it has gone.
So let's actually create our code now inside the main main.cpp file.
Let's actually as you can see, our main file is empty and we will write it on the Main.cpp file.
And we firstly need to initialize a list.
So we will first initialize a list.
Which is going to be list.
List.
Here's list and list.
Here.
We will add several items to the list, which is actually list dot insert.
Uh, the list at insert from on index zero 21.
List at insert.
Index 1 to 99.
Index to 87.
Let's insert some items like let's insert actually five items.
Let's start.
Insert index three.
6 to 9.
List that insert index for.
50.
55 or let's actually do it more different.
Decimal the 30.
35.
Yeah.
Here, this.
We added several items to the list and we also indexed value index value index value and index value
here.
So now we will print the current list.
So in order to print that, we will use a C out list here.
List elements here and after that inline.
Now we will use the for loop to print this list.
For E here zero.
While E is less than list dot count.
So as you know, we have a count which will return our list count here.
So.
Here list.com and then.
Um, e plus plus increment E by one plus, plus e here.
After that, we will use the C out list to get our index E here.
So as you know, the index e will go through zero one, two, three, four, and after the five, it
will be broken here.
So that's why the we are getting every time different items.
So that's why iterating so but I think you learned that in previous lectures so I will not mention it
again.
So here.
Now we printed our list items using for loop, and after that we will see out.
Actually, yeah we will.
After that we will use the end.
And here.
End line.
And line and and line two and line here.
Now we will insert several items in the middle of the list here.
List dot insert 225.
For example in second and let's start insert list dot insert two.
Uh, 61 here.
Now we will print the list again.
Uh, so in order to print it, we will copy this.
Actually, we can do it here.
C out new list elements.
List elements here and line.
And after that we will use the for loop.
For loop.
The integer is here zero while e is less than uh, list dot count and then it will iterate increment
by one.
After that we will see out the list.
Dot, get here E and after that.
Inline.
Yeah.
End line.
And the section make it to lines and lines here.
So now let's actually search here.
Now we use the inserts and now let's actually use the search here.
So we also use the get insert.
Now we're going to use the search.
Here now we're going to search.
So, for example, let's actually search the value.
61 So actually add the comments, search the value 69 and here see out search element 70 or 61 and after
that inline again.
So we will.
Create a new integer called result.
Integer result list dot search.
61.
And if the result result.
Result is my equals to minus one.
So as you remember the search item here, the search item here will return.
The search item will return.
Minus one, if the list is not found here, will return minus one if the list is not found.
So let's delete this again and come here.
Here.
So then it will see out.
The 61 is not found if if the result is equal to minus one.
So 61.
Is not found.
And after that, again, end line, end line here.
If the else happens, then the else statement in this case, it's that it means it found our.
Index.
So else.
See out, 61 is found at index and we will pass the index here.
The index is in this case, index is result and end line.
Here.
So we also use the search here.
We also use the search here.
Now, let's actually use the remove method here.
So now after that, we will use the remote view and do some actions with it.
So let's actually write a remove element at index three or index two.
And here in line after that, we will release that remove tube.
For example, since we are telling the user that we are going to remove the index at tube.
So now.
We will remove use the remove method and after that.
Actually, we do.
Do we print anything?
Yeah.
Then now we don't need anything here.
So now let's actually print the list again.
Signs here.
Prints the list again.
Print the list again.
So see out new list elements here and line after that for integer here equals zero zero.
While e is less than list that get get count or.
Or count here and increment a by one.
After that, we will print the list, that list item each time.
And line.
And here.
We will also search the volume value of 71 again here, 60, 61 again.
So search the value 61 again to check if it is removed here.
Now see out.
Search the element 71 or 61 again and after the line.
Now the result is going to be less that search.
71.
So as again, if our the result if our result is equal to minus one.
So this means we couldn't find anything and we will print the user that 71 is not found or 71.
61.
Oops, not 71.
Sorry.
So 70.
61.
Is not fond.
And after that line here.
So else if the else happens.
If else happens.
But why?
It's showing.
Result list search here.
So if else happens.
Then print the user that 61 is found at index.
And this is our result.
We will print the result integer here and then line here.
And after that we are done with our code here.
So fortunately, our list datatype works well and we can apply all the operation that list should have.
So here let's actually open clear CLS.
So if you build and run this application here.
So it was main.cpp and yeah.
G plus plus color.
G plus plus.
Cplusplus.
Main.cpp.
And as you can see, we get an error.
Let's actually compile it and on the machine and see what happens.
So 78.
Yeah, we have undefined reference.
So we didn't actually define this count yet.
So we also we will also need to define count.
So.
Here.
And that's the integer discount returns in just an integer.
So here.
Uh, integers.
List count.
So the count is going to be.
Here.
Now we're going to develop our count.
Count method here.
So the count method returns integer.
This means that we're going to use return just and return our.
Our first lecture.
Create the count.
My array count.
Or do we have the count here?
Count by default?
No, we don't have anything like that.
So.
Yes.
Integer.
My count here equals the size of.
Size of our array, which is going to be the size of our array is going to be like the.
My items, size of my items, my items and we will use multiply it by divided by size of our my items.
Here.
We also have the my count here.
It's actually.
Yes.
My count.
So we also have the Mekons.
So.
Um.
Uh, size of items.
And.
Size of my items and.
Yeah.
We will use the index and zero here.
So that's it.
Let's actually run our program.
I think it will give it an error.
Yes, it will give a no return statement, the function.
So, yes, we need to return statement here, return my count, and let's run the program again.
And as you can see here, we get an error.
The thing is.
Undefined reference to the list list here.
And as you can see here, the list that Conte will return as the conte of our race.