Answers for "priority queue own comparator c++"

C++
0

how to use priority queue comparator stl c++

void SamplePriorityQueueWithLamda()
{
    // using lambda to compare elements.
    auto compare = [](int lhs, int rhs)
                {
                    return lhs < rhs;
                };

    std::priority_queue<int, std::vector<int>, decltype(compare)> q(compare);

    for(int n : {1,8,5,6,3,4,0,9,7,2})
        q.push(n);


    printQueue(q);
}
Posted by: Guest on April-11-2021

Code answers related to "priority queue own comparator c++"

Browse Popular Code Answers by Language