2

学习 C++,我正在阅读标准算法,参考页面在 partial_sort 上说以下内容:

partial_sort: sorts the first N elements of a range

但是当我单击函数的名称时,这就是它对同一函数的含义:

Rearranges elements such that the range [first, middle) contains the sorted middle − first smallest
elements in the range [first, last).

The order of equal elements is not guaranteed to be preserved. The order of the remaining elements
in the range [middle, last) is unspecified.

我看不出这两个怎么一样!考虑到将要排序的项目包含partial_sort一个迭代器 ( middle) 的事实,我认为它与“top N”不同。如果我想使用这个输入来实现“top N”,这意味着我必须有一个指向集合的第 N 个项目的迭代器。但是如果列表没有排序,我怎么知道哪一项是第 N 项呢?

4

0 回答 0