Chuyên mục
Internet

std::priority_queue In C++

Rate this post



In this video we will learn about std::priority_queue in C++ STL. NOTES: 0. std::priority_queue is a container adaptor that provides constant time lookup of the …

Tag: priority queue c++, [vid_tags]

Xem thêm: https://meohay360.com/category/internet

Nguồn: https://meohay360.com

19 trả lời trong “std::priority_queue In C++”

Thanks a lot for the video but I have a few questions:

1. First of all, if we want to order something in ascending order then it is the by default thing or we can pass `std::less` operator. But, here to sort everything, we are passing `std::greater` operator! Doesn't it seem strange?

2. As you mentioned, to sort in ascending order we have to write like: `std::priority_queue<int, std::vector<int>, std::greater<int> >` But, why are we passing `std::vector<int>` and not just `std::greater<int>`? In the case of vector, we just pass `std::greater`, right?

And if we have to pass `std::vector<int>` then why that's not the case with descending order? I mean by default it will assume `std::less<int>` operator but what about `std::vector<int>`? It will assume that one too?

Thanks in advance!

Trả lời

Email của bạn sẽ không được hiển thị công khai.