C++ Priority queue

2021. 3. 26. 15:17·C++/Library

Priority queue

  • <queue> 라이브러리

기본 예제

  • 원소 간에 우선순위가 존재한다.

  • 템플릿으로 클래스를 사용하려면 비교 연산자 오버로딩을 해야한다.

    #include <iostream>
    #include <queue>
    
    int            main()
    {
      using namespace std;
    
      priority_queue<int> queue;
    
      for (const int n : {1, 8, 5, 6, 3, 4, 0, 9, 7, 2})
        queue.push(n);
    
      for (int i = 0; i < 10; ++i)
      {
        cout << queue.top() << endl;
        queue.pop();
      }
    }
    
    /* stdout stderr
    9
    8
    7
    6
    5
    4
    3
    2
    1
    0
    */
저작자표시 (새창열림)

'C++ > Library' 카테고리의 다른 글

C++ set  (0) 2021.03.26
C++ Associative Containers  (0) 2021.03.26
C++ queue  (0) 2021.03.26
C++ stack  (0) 2021.03.26
C++ Container Adaptors  (0) 2021.03.24
'C++/Library' 카테고리의 다른 글
  • C++ set
  • C++ Associative Containers
  • C++ queue
  • C++ stack
Caniro
Caniro
  • Caniro
    Minimalism
    Caniro
  • 전체
    오늘
    어제
    • 분류 전체보기 (317)
      • Algorithm (13)
        • 알기 쉬운 알고리즘 (10)
        • Search (1)
        • Sort (2)
      • Arduino (0)
      • C++ (185)
        • Class (46)
        • Exception (6)
        • Library (51)
        • Overloading (10)
        • SmartPointer (5)
        • Syntax (33)
        • TBC++ (23)
        • Templates (9)
        • VisualStudio (2)
      • Embedded (1)
      • Git (4)
      • Java (5)
      • Linux (16)
        • Error (1)
        • Linux Structure (11)
      • MacOS (7)
      • OS (1)
        • Concurrency (1)
      • Python (21)
        • Class (1)
        • Function (2)
        • Syntax (17)
      • Raspberrypi (9)
      • Review (1)
      • Utility (12)
        • VSCode (5)
        • VirtualBox (3)
      • Web (8)
        • Nginx (1)
        • React (3)
        • Django (1)
      • Windows (20)
        • Registry (3)
        • WSL (1)
        • DeviceDriver (6)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    제외
    SFC
    EXCLUDE
    SunOS 5.1
    맥북 카카오톡 알림 안뜸
    스프링 프레임워크 핵심 기술
    시스템 복구
    MacOS
    spring
    윈도우 명령어
    그림판
    윈도우
    스프링
    백기선
    로지텍 마우스 제스처
    KakaoTalk
    citrix workspace
    logi options
    vscode
    windows
    알림
    Solaris 10
    Windows 11
    dism
    Workspace
    java
    mspaint
    unix
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
Caniro
C++ Priority queue
상단으로

티스토리툴바