Hi, everyone.
So in this video, we are going to solve this question for all the politicians of an element.
So, for example, if this is your ready, five, six, five, six and six.
Index zero, one, two, three and four.
Let's say the value of excess five, so five is present at index zero at the next two.
So five is present at zero at the next two.
So we have a really solid discussion.
But in that question, we were printing.
So we were not storing.
We were printing only.
But in this question, what we need to do so we need to store the position, some of the value of excess
sex, so sex is the next one at the next three at the next four.
So we need to store these indexes one, three and four.
So we need to store this index and we do not need to print.
So the question is a little bit different.
We need to store.
So whenever you want to store multiple things so we can use every.
Or we can use vector.
So we can use that to store or we can use vector to store.
So what we do, we will modify our solution for all position.
If you remember, we have already sold this question print operation, so we'll just modify it.
So instead of printing what we will do, we will pass a vector ordinary and we will store the indexes
inside that vector sample.
So what we need to do.
This is our Brendle position function, we just need to update this function, so let's copy this function
and we will update.
So let's remove it from here.
So what to do to change the name of the function so we will not print.
We will save.
Seybold position.
So for saving the position, what do we need to do?
We need to take that as input or we'll take that input.
So let's say I am taking a vector as input vector in, let's say answer.
So this Victor of all the politicians.
So, Victor.
The Jesus answer, this letter is initially empty, let's call this function, see what position.
I will pass, Eddie, I will pass and I will pass, I will pass starting next, which is zero.
So the value of this I want to search for, I want to store all the positions for five zero is the starting
next.
And I need to pass the vector, which is answer.
So what will happen, dysfunction?
Will update this letter and then I need to print that letter to check whether the output is right or
wrong, so let's the vector so I equals zero I less than what size I placeless.
Setout.
And set off a.
So let's rename the vector to the Vector V. I am passing the pervy.
And this is the profi.
Simple, so there is one problem with this code and it is the problem, so we need to pass the Turbit
offense because we want whatever changes the evaluation function do.
So all the changes should be reflected in this report also.
OK, so we need to pass it by reference and let's update this function.
So if I Coalson, I am returning.
So instead of printing, instead of printing the index, I restore the index.
So answer not wish back.
We will not print the index, we will store the index pushed back I.
And here we need to pass director answer Victor.
OK, so I think our court will work and we need to change.
So this is not this is save save oil pollution.
OK, so I think our function will work.
So I am printing all the positions of five.
So five is present at present zero, one and three.
So I am using Vector, but I have not included the header file, so let's include the added file.
So the output should be one, three and five.
And what's the error here?
OK, so basically it doesn't know what is and is basically the number of elements, which is six one,
two, three, four, five and six.
So element five is present, it makes it Heidi Nexon added in next.
So our function is working.
So let's see.
So let's give the value six six present to the next two and four.
Success by then next to.
Let's give the next seven.
Seven is that next five, so I put this five and let's give a value which is not present, so output
should be empty, our factories and producers will not print anything.
So basically, our function is working.
So a better way of solving this problem is I told you, either we can use Vector who stole the data
or we can use it to store the data.
It is our choice.
So now let us use a.
Let's use that.
We see how we can use vector.
So now let us also use Eddie.
So let's create another function.
Control and control.
So this time I will not take the president, but I will take that as input.
I was told the output inside the.
So the name of the ad is output very.
OK, so you are pushing the element now how we can push element inside the output area, so we're pushing
the element inside the area to take when it looks at what next, you need to push the element.
So I'm taking the Next G.
So this Next G will start from zero.
And the next is for output three.
So I want to insert my element, I want to insert my element at the Next G, so output, so output of
G.
It's a simple.
And then to do so, you have to call this function, save all position.
So let's Nimmitabel position.
Using Adi.
So let's copy the function table position using Eddie.
So I am calling the function stable position instead of I said I have output vector and I need to give
J plus one, but I think this is wrong.
Why it is wrong.
See, I need to write one more call here.
So if you are storing the answer, invariably, then you need to pass J plus one simple.
You are passing J plus one.
But when you are not storing the output then you need to pass.
OK, sometimes we need to pass g sometimes we need to pass J plus one.
So I need to write one more call here, so here I am not interrupting anything, R.G..
So if I didn't Next X is not present, then I will pass only no changes, but in fact I am the next
president.
So I mean, starting next year, I starting next I the next year.
So now I need to call this function.
And I will pass at a number of elements X I plus one, obviously, and now G plus one.
So you need Jay here and you need a plus one here, OK, you know, Vijaya plus one because at the Next
G, you're inserting this element simple.
So now I think our function will work fine, so let's test our function, so let's give a line here.
So let's create an output area and let's say the size is Ben, I'm creating an output aerial system
and let's call this function.
See oil pollution using it.
I will give that as input number of elements is basically six.
The value of, let's say, five.
I will start from zero.
I need to parse the output today, so output, Terry and I need to pass the next four output.
So for next year, I will start pushing from zero in at the start from zero.
And I think our function will work fine.
So all the elements, all the values will be inserted inside our output very fine.
So when thing see here we are passing vector Bio-Reference because by default that are passed by value.
But we know it is passed by reference always.
So I think our function will work.
So now the question is how we can print our output very.
So footprinting, if you want to paint, if you want to paint a picture, you can paint it like this,
you have Daudzai function, but not if I want to print my output.
So how can I bring to my output?
So I used to print an array like this equals zero iList and I plus plus so and I don't know what is.
And so I don't know how many elements are present inside of my output that I cannot write down here.
I cannot write a list and then that will be wrong.
So five president, only three times, so first he will be occupied, firstly, positions will be occupied
first and second and third question.
All the rest will be garbage.
So I cannot use 10.
So how to find out how many elements I have inserted inside my area.
So how we can find that.
So if you remember, we have sort of count occurrence.
We have civil discourse in Congress, so what you can do, I can call the function Congress and it will
give me how many times five is appearing.
So it will give me five is appearing three times.
So I know that my vector is containing three indexes.
So instead of and what can I do?
I can use countercurrent.
Simply.
So I can use countercurrent.
OK, so what will do so let's change the return type of the function so dysfunctional, done integer.
Integer means it will return how many times the element is present.
So instead of calling this function.
I will call return one plus.
And here I will return zero plus, and here I will return zero, so I am doing two things.
I am doing two things with this function, I'm storing the output, I am storing the output, and for
storing the output.
I am taking an output it as well as the index.
So this is the output array and this is the index.
The value of the will start from zero.
So I'm inserting the element.
So I need to write output here, output, energy plus one.
And this function is doing one more thing and that thing is basically count count occurrence.
So if I it is in return zero, if X is present at the next high return one plus otherwise done zero
plus.
So, so this function will return how many times the value is present inside the array.
So I need to write output here.
OK, so this function will return the count.
COUNTERCURRENT, how many times the element is present, so let's simply name it count.
And now.
We can print our.
So I equals zero, I didn't count.
I placeless.
Setout.
Output of.
So what I'm doing here is so I told you I had to bring to my area, my area is of size 10, but only
the three values.
But FIFA's president only three times, so zero one.
And this is three.
So zero is president there.
One is president there and three is presented at all.
Values are garbage.
So I cannot bring to my area like this and I equals zero, i.e. less than 10.
I cannot righton if my size of the arrest and so I cannot return here.
I need to write three.
And what is three.
The number of times is present.
So in vector we have the function so it will give me three.
But in it if we do not have to use function.
So if you remember, we have written the code for count occurrence function.
And how does condo construction work so they will be integer eight zero from here if you find the value
it used to call one plus recursion and it used to call zero plus equation.
So this function has all the properties of countercurrent, so this function will return three.
So I am storing that in this variable three and I'm using three here.
So that's how it will work.
OK, so this function is working exactly like countercurrent function, but it is also storing the output
here.
Simple, so now let us test our function.
OK, so what is happening here?
So this is this was about three, five, five, six, five, six and seven.
So first I am painting director but I'm giving 10.
So 10 is not pleasant.
And so I decided.
So I will not print anything, which is basically zero zero deadline.
So go to the next line.
So after reaching the next line, if you see that we are searching for data five, data five is present
at index zero at the next one at the next three.
And we are printing and then we are giving and line so it zero and next one and next three.
So we are giving and that's why the output is coming out in different lines.
So let's test our function one more time.
So let's give Speciate.
And let's say I want to search for sex success the next to and for.
So 24.
Seven, OK, so I need to give seven.
I am testing for seven.
So when is the next five, so five is the output.
And let's test it one more time then, is not present inside the area.
So basically the value count will be zero and I will not go inside this for loop, so I will not print
anything.
So I am not printing anything.
So this is how you can write the code.
OK, so this is it from this video.
I will see you in the next one.