1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

std::multisetに比較関数を定義したい

Last updated at Posted at 2022-03-03

やりたいこと

std::multisetやstd::setを降順で定義したい

case1 降順で定義したい

各要素に-1をかければいいじゃん?←ダサい

compareという比較関数を定義
using namespace std;
typedef pair<long long, long long> pll;

auto compare = [](const pll a, const pll b) { return a > b; };
multiset<pll, decltype(compare)> ms{compare};

pairにはあらかじめ比較関数が定義されているので、ok
これで例えばイテレータをms.begin()から回した場合、要素を降順に取り出すことができる

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?