Skip to content

Latest commit

 

History

History
84 lines (59 loc) · 1.74 KB

sort.md

File metadata and controls

84 lines (59 loc) · 1.74 KB

sort

  • hive[meta header]
  • std[meta namespace]
  • hive[meta class]
  • function[meta id-type]
  • cpp26[meta cpp]
  • [mathjax enable]
template <class Compare = less<T>>
void sort(Compare comp = Compare()); // (1) C++26
  • less[link /reference/functional/less.md]

概要

要素を並べ替える。

事前条件

型Tがhiveに対してMoveInsertableであり、かつMoveAssignableかつSwappableであること。

効果

関数オブジェクトcompに基いて*thisの要素を並べ替える。例外が送出された場合、*thisの要素の順序は未規定である。

戻り値

なし

計算量

Nをsize()として、$O(N \log N)$回の比較

備考

  • メモリを確保する可能性がある。
  • *thisの要素を指す参照・ポインタ・イテレータ、および終端イテレータは無効化される可能性がある。
  • この操作は安定であることを要求されない。

例

#include <hive>
#include <print>

int main()
{
  std::hive<int> h = {3, 1, 4, 1, 5, 2};

  // 昇順に並べ替える
  h.sort();

  for (int x : h) {
    std::print("{} ", x);
  }
  std::println("");
}
  • sort[color ff0000]

出力

1 1 2 3 4 5 

バージョン

言語

  • C++26

処理系

関連項目

参照