sort関数の使用

496 ワード

  • sort関数を使用するヘッダファイル#include
  • を使用する
  • 関数形式:void sort(RandomAccessIterator first,RandomAccessIterator last,Compare com)作用:[first,last)範囲クラスで昇順ソートを行い、等しい要素はソート後の相対順序が変化しないことを保証できない(すなわち、不安定なソート).3番目のパラメータcomはbool型関数であり、デフォルトである.
  • 平均時間複雑度:NlogN;

  • 比較関数comを定義し、降順に変更します.
    #include
    #include
    std using namespace;
    bool compare(int a,int b){
        return a S;
    sort(S.begin(),s.end(),compare);