우선순위 큐 정렬 방식

Worldi·2021년 12월 5일
0

알고리즘

목록 보기
29/59

우선 순위 큐

선언

priorty_queue<자료형, Container ,비교 함수> 변수명.

정렬 방식

struct cmp {
bool operator () (int n1, int n2)
{if ( n1> n2 ) 
return true;
else return false;
}
}

priority_queue<자료형, Container, cmp> 변수명

응용

typedef struct _edges
{
    int to;
    int cost;
} Edges;
struct cmp
{
    bool operator()(Edges e1, Edges e2)
    {
        if (e1.cost > e2.cost)
            return true;
        else
            return false;
    }
};
priority_queue<Edges, vector<Edges>, cmp> pq;

출처

https://travelbeeee.tistory.com/126

profile
https://worldi.tistory.com/ 로 블로그 이전합니다.

0개의 댓글