Hi, everyone.
So in the last few videos, we discussed how we can implement our own priorities.
We discussed how we can write the code for implementing in place Cheapside.
So in this video, we will try to learn about the inbuilt priority queue.
So the priority is actually president didn't steal and attempted bribery in C++.
So this inbuilt priority queue.
So this is this is present in UCLASS.
Now, if you want to solve a question using a priority, you so suppose in future, if there a question
and in order to solve that question, you want to use priority queue, then you will not implement tried
give yourself you're just likely use the prior deal that is implemented in the standard library.
So now let's see how we can use the inbuilt priority queue.
So first of all, what are the functions that we implemented ourselves?
So I implement, we implemented a function is empty.
Now, an inbuilt priority, guilt or dysfunction, is also present with the name empty again, there
will be boolean, true or false is my cue.
Importunate is my priority, QM, but they are not.
Similarly, we implemented our function getset.
So this function is also present in priority.
GICLAS And the name is basically size, so this will return me an integer.
So this will return integer.
And similarly we implemented a function insert.
Now insert function will take an element as input and it will insert into our prior dequeue.
Similarly, we also have inbuilt function push.
And this Bush can take the element of any type Sorte element, so actually this class, so this private
class, so this is implemented using template.
So that's why you type and element now, we also implemented a function, get a minimum.
Similarly, there is also a function in private vehicles and of the function is top, so I will call
the function top and it will give me the Menom element again.
The type will be the sort DAYTOP These the type of Lesedi type of the element, simple.
Now reimplemented one more function, remove minimum function so reimplemented remove minimum function.
And what it does is so in our implementation it will lead the element and it will also return the element.
So in our implementation we were returning integer.
So in our implementation it will remove the element and it will also give me that element.
But in the inbuilt protocol, it will just pop out that element.
So why'd Bob?
So basically, this bulb function, it will just remove the element, it will not give us the element,
but in our implementation, we implemented it in such a way that it will be the element and it will
also return the little element.
Now, let's try to use our in particular to see the cold.
So first of all, this protocol is present in UCLASS, so I have to include that class in order to use
prior to Q.
Now, the syntax is very simple, we have to write priority due, so Priority and Corkill and the name
is Piku, but obviously this is wrong because this particular priority class is actually a template,
so template.
So that means you have to give the type.
So suppose I want to create a priority queue often teachers.
And now let us push some elements.
So, again, for pushing the element, I have a function I haven't built function, be good art.
Bush and I will give Integer here because I have given I am creating Plastiki, often tedious.
So that's why this push function will take integers and put.
So let's say 16 and let's copy this Bush and let us insert more elements.
So let's see, the elements are one, then let's see 167, then let's see.
I want to insert seven, then let's say 45, then let's say 32.
So I am inserting I am pushing six elements into my priority queue, simple, let's see other functions
that involve function of radical glass.
So let us first try to print this size.
So forgetting the size, we have inbuilt function size.
So I will write be good size.
So the size is again inbuilt function of our practical class.
So it will return me six because I am pushing six elements to the size of our priority is actually six.
Simple.
Now, let's try to find out the top element, so I am trying to pin the top elements of what should
be my output to the function is be good top.
So the stop function, it will return me the element present at the root element.
So what should be my output?
So one thing to notice here is.
Basically, so this output depends upon so this element depends upon whether you are creating a minimum
or you are creating a maximum heap.
So this is actually maximum cheap.
This is the index for creating maximum.
It also discuss how we can write this index for the minimum heap, but not in this video.
So this is actually makes me.
So what will happen to these elements are present in maximum heap and size will give me the six and
picador top.
So what it will give me.
So it will give me the root element.
And in case of maximum, the root element is the largest element.
And the largest element is actually 167, so the output of this line is going to be 167 simple.
So now let us try to bring all the elements so we can use.
So this will be one six to seven because this is actually maximum cheap.
Again, we will also discuss how we can write the code for the minimum, but not in this video.
So, again, very simple and so vital priority queue is not empty, but we have to do so, we will get
one by one and we will bring the element.
So, again, she would be good or so it will give me the top element, basically the largest element,
and then what I will be good artpop, I will remove this largest element.
So what I'm doing, I am blending the topmost element, which is going to be the largest element, and
then I am popping out the Taliban symbol.
So let's see what will be our output.
OK, so this is spelling mistake.
Now, this is correct.
OK, so compilation error.
So as we can see now, let's try to analyze our output, so as I told you so this is actually a maximum
EHP.
I am pushing six elements, so that's why the size is going to be six and the topmost element is going
to be 167.
So this is my hip maximum 16, then one, then 167, then seven, then 45 and then 32.
So while prior to queue is not empty, so picador top, so top most elements one six to seven to bring
the topmost element and remove the top most elements.
So 167.
So this is more and six to 167.
Then again prior to Goozner temporary bring to the up most elements or top master element is 45.
So after printing the element also remember that element.
So let's a 45 here.
Similarly, again, the priority is not empty.
So the maximum element and pop the maximum element.
Bring the maximum element and maximum element, bring the maximum element and maximum element into the
maximum element and maximum element.
And finally, this condition will become false because now my priority is actually empty.
So I will come out of this very simple.
Now, again, if you want to discuss so what is their time, complexity for push function, so we have
this question many times the time complexities log of in.
So in prior to kill, all the functions are going to take longer in time.
So Bush is going to take longer in time.
Now the sites function.
So this is constant.
We are just returning the site again, top element.
So we just have a and root element.
So again, this is constant.
So again, this empty function, this is also constant.
So, again, this top function constant, not this pop function, so this pop is actually removable,
so this is log-in.
So.
This empty function, the societys function, they are constant function, so you get the minimum function
is also constant and this push and pop, so this function is actually logoff and and what is and is
basically the total number of elements present in our priority queue.
So is the total number of elements in our Pritikin.
So now we know how to write the code, how to use our inbuilt priority queue, inbuilt maximum priority
queue and we will discuss in the next video.
How we can write, how we can write the code for using minimum hip, so minimum is also in, but the
syntax is a little bit different.
So in this video we discussed only makes one hip and all the functions will be same in the mix.
And he pandamonium hip, all the function will be same.
But just the way of creating is a little bit different, which you will discuss in the next few videos.
So I will see you there.
Bye bye.