Пространства имён
Варианты
Действия

std::sort_heap

Материал из cppreference.com

 
 
Алгоритмы
Функции
Немодифицирующие линейные операции
Модифицирующие линейные операции
Разделение
Сортировка (на отсортированных промежутках)
Бинарный поиск (на отсортированных промежутках)
Множества (на отсортированных промежутках)
Куча
push_heap
pop_heap
sort_heap
Минимум/максимум
Числовые операции
Библиотека C
 
Заголовочный файл <algorithm>
template< class RandomIt >
void sort_heap( RandomIt first, RandomIt last );
(1)
template< class RandomIt, class Compare >
void sort_heap( RandomIt first, RandomIt last, Compare comp );
(2)
Сортировка элементов в куче [first, last) в порядке возрастания. Первая версия функции используется operator< для сравнения элементов, второй использует данную функцию сравнения comp.
Original:
Sorts the elements in the heap [first, last) in ascending order. The first version of the function uses operator< to compare the elements, the second uses the given comparison function comp.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Содержание

[править] Параметры

first, last -
диапазон элементов для сортировки
Original:
the range of elements to sort
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
comp - comparison function which returns ​true if the first argument is less than the second.

The signature of the comparison function should be equivalent to the following:

bool cmp(const Type1 &a, const Type2 &b);

The signature does not need to have const &, but the function must not modify the objects passed to it.
Типы  Type1 и  Type2 должны быть таковы, что объект типа RandomIt может быть разыменован и затем неявно преобразован в оба из них. ​

Требования, накладываемые на типы
-
RandomIt должен соответствовать требованиям ValueSwappable и RandomAccessIterator.
-
Тип разыменованного RandomIt должен соответствовать требованиям MoveAssignable и MoveConstructible.

[править] Возвращаемое значение

(Нет)
Original:
(none)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[править] Сложность

В большинстве N × журнала (N) сравнений, где N=std::distance(first, last).
Original:
At most N×log(N) comparisons where N=std::distance(first, last).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[править] Notes

' Кучу целый ряд элементов [f,l), который имеет следующие свойства:
Original:
A heap is a range of elements [f,l) that has the following properties:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • *f является крупнейшим элементом в ассортименте
    Original:
    *f is the largest element in the range
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • Новый элемент может быть добавлена ​​с помощью std::push_heap()
    Original:
    a new element can be added using std::push_heap()
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • Первый элемент можно удалить с помощью std::pop_heap()
    Original:
    the first element can be removed using std::pop_heap()
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
Фактическое расположение элементов, определяется реализацией.
Original:
The actual arrangement of the elements is implementation defined.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[править] Пример

[править] См. также

создает кучу из ряда элементов
Original:
creates a heap out of a range of elements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(шаблон функции) [edit]