If we are storing something in priority_queue stl,its storing it in either ascending order or descending order,but not storing it as per its priority like that in heap

eg:for maxheap
if insertion is:5 1 4
user defined heap will print 5 1 4
priority queue stl will print 5 4 1
There is a difference in printing .Why it is?
priority queue stl is just sorting the elements.,not storing as per our user defined heap

heap is the internally implementation of priority queue
after inserting 5 1 4
if you print the heap means
you print first element then pop then print
in this way it will also print the same result as of priority queue

but you are just print the array/container in which heap stores it;s data
but in priority queue you can’t print the container in this priority queue stores its data

i hope now its clear why there is difference in output
because in case of heap you are printing the container in which heap store the data
if you print heap like priority queue it will give same ans

Yup now it is cleared.Please also explain greater function and its working.

greater is inbuild comparsion function
it is simple function
it’s implementation is like

template <class T> struct greater : binary_function <T,T,bool> {
  bool operator() (const T& x, const T& y) const {return x>y;}
};

you read about it in detail at documentation

greater<> Documentation

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.