Hi, everyone.
So in this video, what we will do, we will write the code for this much heart function and we will
write the code for Mojada function.
So let's discuss about thought.
So the approach is very simple.
This is a you know, the starting index, you know, the index, so we know starting, we know and we
will find out.
So it will be a start plus.
And by doing so, we'll create another X.
And we will copy all these elements.
So let's do let's write the code for this much.
So what we need to do, first of all, we need to find out the mid.
So let's start by doing so after finding out mood, we will create and ATX.
Let's say the site is held and we need to copy the elements, so I equals zero, I lost an order custommade
I placeless.
So Zulfi is sort of a symbol, so what we are doing, so this is murder, somebody will be here.
And this is our start.
So we copied all these elements in.
OK, so now what we need to do, we will create another area.
Let's create another area.
And what I'm planning to do is I will.
So this is my area.
If this is my area, I.
So I will copy the elements here, I will copy the elements here, and I will not copy the elements
at the beginning.
OK, so I will copy the elements at this position.
So basically what I want to say is if this is my area one, two, three, four, five and six, what
I want to do.
So my ex said, this is my Addicks, this is Arrietty, this is my Eriks, so for Eriks, I'm copying
the elements like this.
OK, one, two and three.
You can see I and I, so basically is Aasim and this is our Ariva.
So I'm copying my elements like this for will come here.
Five will come here and six will come here.
Basically, these values are garbage.
OK, these are garbage.
So basically index will remain so for this president, let's say zero, one, two and three.
So for the next three.
So Environmental four will be present at the next three.
Simple.
So let's we need to create one more ready very let's say the site is under and we need to copy the elements.
So I will start copy from the one so I left tonight request to end I placeless.
So why Yoffie is it goes to a very simple.
So what I'm doing here is see.
This is so starting and this is a middle class, and so this element has an X plus one, so I will start
copy from my next meal plus one till the end.
So this is my plus one index and we will copy all these elements.
And the index is the same IRONI.
So that's why four will be here, five will be here and six will be here.
So if you do not like this approach vertical, so you can put four, five and six here also what do
you do to do right here.
Something like so you tried something like this.
I minus mid minus one I think so if the value of this only plus if the value of it is made a plus one.
So value if I use made plus one and minus plus one.
So that will be present at the next zero.
OK, so if you do not like this approach, if you do not want to copied elements like this, if you
want to add elements to be at the present at the first patrician's.
So four, five and six so you can use this i.e. minus made of minus one equals if you can use any of
them.
OK, it's your choice.
So now I have to add is really X and Y, so I have to whereas ready X and Y, what you need to do,
we need to call the regression on these two areas.
We need to apply my on these two areas.
So let's apply the Mozart, let's copy Mozart.
Muttered Ex, starting and made.
My thought is why starting is middle one and snowboarder's has been sorted.
So what will happen?
So what is the situation right now?
So this area, so it is already sorted and let's take another area.
So if this is already seven, three, one, five, six and two.
So Erich's is basically 71, so after playing them, I thought on this.
Now this area has been sorted.
So basically X-rays one, three and seven simple and decide if I was five, six and two starting points
are containing garbage value.
This is five, six and two.
This is why.
And what they are doing, you got to playing them much harder.
So this area has now been sorted to starting position are empty and this will become two, five and
six.
So this position is basically middle plus one.
This is the starting position and this is the middle position and this is the of position.
So now Exodus started, Aviad is sorted.
So what do.
We will call this function, Marjorie.
We will give every expert, we give everybody.
We will give away and we will give you starting next.
We will give the index.
So let's write the code for the Mercedes.
So what do we do?
Let's call the function Margery's.
So I will give X, which is the area which is ordered area which which need to be sorted, starting
index and index.
And now let us write the code for the majority function.
So how we can write the code for Margery's.
So what we will do I will compare this element one with element to which on is smaller, one is smaller,
so I will put one.
So basically, let's take variables, let's take a variable.
I add this index and let's take a variable JRD index.
So I will move in this direction, will move in this direction.
So let's take variable, let's take two variables.
And so let's find out the first.
So let's start listening to.
Start lessened by.
So what is I.
So I start and what is Jay so Jay's made plus one.
So what I'm doing so this is I I to start and this is Jay, so Jay Z metabolism, so Jay Z metabolism.
So I will move in this direction.
Jay will move in this direction, which will be smaller.
So one is smaller.
So I will put one and I will move forward similarly then I will come back you and also to smaller I
will put two and Jay will move forward.
OK, so this is very simple problem.
You have this, all this problem somewhere that you thought that is.
So let's take a variable key for this area.
So start from start.
OK, so let's take a variable K so K will be starting from the starting index starting next.
OK.
So basically, this index I use for attriting or X, the index is for our over the next case, for our
trading, our.
And what condition we need to use.
So while I.
Is less than the custommade, Vijay is less than I was to end.
I will do the comparison.
So the correlation is very simple.
So while I is less than our customer and Jay should be less than what it cost to end, so we need to
do the comparison.
So if the value eye is smaller, so if X or Y is it smaller than Vitalogy, then in that case it will
be X or Y, so I will move forward and will move forward in the sales part, what they can do.
So in the early part, the value of that index is smaller.
So Aoki will be Buyology, so J will move forward and will move forward.
Simple.
So what I'm doing.
So compare one and two.
So one is smaller.
I will put one here and now I is present at this index.
So compare three with five.
So compared it to so two will be here and G will move forward.
So J is that the next five.
So just pointing to value five.
So compare three and five.
They will be here and guess moving forward.
OK is moving forward.
So three will be present then I will reach seven.
So you will compare seven with five.
So you will put five J will be present at that element six.
So you will compare seven and six, seven, six will be here.
So J will reach the end.
So J will reach.
So G will become.
And plus one when you will reach.
And plus one you will come out of this via loop.
And these are the elements.
One, two, three, four, five and six.
So basically one element is remaining, OK, so what to do.
So basically there are two ways.
So there are two ways that I can come out of this loop, the value of I will become the person or the
value will become.
And so we need to copy the rest of the elements.
So let's copy the rest of the elements.
So while.
I is less than ideal.
We need to copy the elements so AFIK.
Will be ex of a Gabler's plus and plus plus similarly, we need to copy the rest of the elements.
So while Jay is listing articles two and.
So AFIK will be Ryoji and he will do Gabler's plus you will lose C++, so this is the code for the majority
function.
So our majority function will work properly.
So that is how you can write the code for my chart base case.
Very simple.
Zero element or one element.
Find out the word copied the elements.
Greatorex and we saw the two areas and then master to order that is.
So let's call this function Mussert and let's see whether our code is right or wrong.
So let's copy the function.
So my thought I have to give and I had to give the starting next, and I intend to give the last index,
so let's create an area first.
So if this is my area.
And let's say these elements are seven cometary coma, one coma, five coma, six comatose.
So these are six elements.
So the last next will be five.
And now let us print the ad so that we can see so I equals zero, I elastin six I placeless.
Setout.
Afie.
So let's test our function.
OK, so basically there is something wrong.
The function is not working.
So let's see what is the mistake.
So let's start from here.
Start with an end.
So this is wrong.
This will be a less than ideal standard.
Let's test again.
And now the elements are getting sorted.
OK, so you can compare the elements for three one, five, six, two, and this is one, two, three,
four, five and six.
So basically our function is working.
So let's give some more elements.
Let's say this is element seven and this is element that certain.
And let's add one or two more elements.
Let's say three.
So three is already.
Let's make it minus five and let's add 78.
So now the number of elements is one, two, three, four, five, six, seven and eight.
So last election next will be seven and here it will be aired.
So let's call the function mushahid.
So basically, you can see that is getting started minus five, two, three, five, six, seven, 10
and seven.
So basically our function is working.
So let's consider one case in which the number of elements are basically.
So these are the even number of elements let's test for.
So let's remove an element.
So the last word next will be six and the number of elements is seven.
So you can see our function is still working, our area is getting started and how it is getting sorted.
So let me diren you one example, what you will do.
So if this is you ready seven three one five six two.
What you will do, you will do.
I do that into two 1/2.
So this will be 70 and when I'm dividing the areas into two 1/2.
This will be basically five, six, two, you are playing Mozart on board half, so this idea will become
one three seven decide, it will become two six five.
And you are merging the two sort of you are merging to sort it out.
So one, two, three, five, six and seven.
So that is how it is working.
So another way is basically it's seven three, one, five, six and two.
This is our already.
I told you that working it will be split it into two 1/2, seven driven and five six to.
So the number of animals is also basically one side they will be to eliminate and either side there
will be one element.
So let's see the side.
I have only one element and the right side I have two elements, three and one.
Similarly, this will be five.
And let's say the other side, I have to eliminate six and two.
So similarly, this will be six and this will be two.
So this will be three.
This will be one.
And now we will hear the case.
So element one, so start is here and this here, Leontes one.
So this is also sorted, sorted, sorted, sorted, merge these two.
So it will be one entry.
So this is a sort of that this is a sorted area must not lose order, that is so after merging the two
sort of that is it will be one through seven so much these two areas.
So these two areas are basically sorted.
So it will be two six.
This is also sorted out.
So after merging, it will be two, five, six.
So now this area is basically sorted.
This area is basically sorted mostly to certain areas and they will get a certain area, which is one,
two, three, five, six and seven.
So that is how this function is working.
This is my third function is working.
So this is from this video.
I will see you in the next one.
Thank you.