Standard Template Library Programmer's Guide

Здесь есть возможность читать онлайн «Standard Template Library Programmer's Guide» весь текст электронной книги совершенно бесплатно (целиком полную версию без сокращений). В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Жанр: Программирование, Справочники, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.

Standard Template Library Programmer's Guide: краткое содержание, описание и аннотация

Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «Standard Template Library Programmer's Guide»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.

This document contains reference on SGI STL implementation

Standard Template Library Programmer's Guide — читать онлайн бесплатно полную книгу (весь текст) целиком

Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «Standard Template Library Programmer's Guide», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать
See also

includes , set_union , set_intersection , set_difference , sort

Heap operations

push_heap

Category: algorithms

Component type: function

Prototype

Push_heap is an overloaded name; there are actually two push_heap functions.

template

void push_heap(RandomAccessIterator first, RandomAccessIterator last);

template

void push_heap(RandomAccessIterator first, RandomAccessIterator last, StrictWeakOrdering comp);

Description

Push_heap adds an element to a heap [1]. It is assumed that [first, last – 1) is already a heap; the element to be added to the heap is *(last – 1) .

The two versions of push_heap differ in how they define whether one element is less than another. The first version compares objects using operator< , and the second compares objects using a function object comp . The postcondition for the first version is that is_heap (first, last) is true , and the postcondition for the second version is that is_heap(first, last, comp) is true .

Definition

Defined in the standard header algorithm, and in the nonstandard backward-compatibility header algo.h.

Requirements on types

For the first version:

• RandomAccessIterator is a model of Random Access Iterator.

• RandomAccessIterator is mutable.

• RandomAccessIterator 's value type is a model of LessThan Comparable.

• The ordering on objects of RandomAccessIterator 's value type is a strict weak ordering , as defined in the LessThan Comparable requirements.

For the second version:

• RandomAccessIterator is a model of Random Access Iterator.

• RandomAccessIterator is mutable.

• StrictWeakOrdering is a model of Strict Weak Ordering.

• RandomAccessIterator 's value type is convertible to StrictWeakOrdering 's argument type.

Preconditions

For the first version:

• [first, last) is a valid range.

• [first, last – 1) is a valid range. That is, [first, last) is nonempty.

• [first, last – 1) is a heap. That is, is_heap(first, last – 1) is true .

For the second version:

• [first, last) is a valid range.

• [first, last – 1) is a valid range. That is, [first, last) is nonempty.

• [first, last) is a heap. That is, is_heap(first, last – 1, comp) is true .

Complexity

Logarithmic. At most log(last – first) comparisons.

Example

int main() {

int A[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

make_heap(A, A + 9);

cout << "[A, A + 9) = ";

copy (A, A + 9, ostream_iterator(cout, " "));

push_heap(A, A + 10);

cout << endl << "[A, A + 10) = ";

copy (A, A + 10, ostream_iterator(cout, " "));

cout << endl;

}

The output is

[A, A + 9) = 8 7 6 3 4 5 2 1 0

[A, A + 10) = 9 8 6 3 7 5 2 1 0 4

Notes

[1] A heap is a particular way of ordering the elements in a range of random access iterators [f, l) . The reason heaps are useful (especially for sorting, or as priority queues) is that they satisfy two important properties. First, *f is the largest element in the heap. Second, it is possible to add an element to a heap (using push_heap ), or to remove *f , in logarithmic time. Internally, a heap is a tree represented as a sequential range. The tree is constructed so that that each node is less than or equal to its parent node.

See also

make_heap , pop_heap , sort_heap , is_heap , sort

pop_heap

Category: algorithms

Component type: function

Prototype

Pop_heap is an overloaded name; there are actually two pop_heap functions.

template

void pop_heap(RandomAccessIterator first, RandomAccessIterator last);

template

inline void pop_heap(RandomAccessIterator first, RandomAccessIterator last, StrictWeakOrdering comp);

Description

Pop_heap removes the largest element (that is, *first ) from the heap [1] [first, last) . The two versions of pop_heap differ in how they define whether one element is less than another. The first version compares objects using operator< , and the second compares objects using a function object comp .

The postcondition for the first version of pop_heap is that is_heap(first, last-1) is true and that *(last – 1) is the element that was removed from the heap. The postcondition for the second version is that is_heap(first, last-1, comp) is true and that *(last – 1) is the element that was removed from the heap. [2]

Definition

Defined in the standard header algorithm, and in the nonstandard backward-compatibility header algo.h.

Requirements on types

For the first version:

• RandomAccessIterator is a model of Random Access Iterator.

• RandomAccessIterator is mutable.

• RandomAccessIterator 's value type is a model of LessThan Comparable.

• The ordering on objects of RandomAccessIterator 's value type is a strict weak ordering , as defined in the LessThan Comparable requirements.

For the second version:

• RandomAccessIterator is a model of Random Access Iterator.

• RandomAccessIterator is mutable.

• StrictWeakOrdering is a model of Strict Weak Ordering.

• RandomAccessIterator 's value type is convertible to StrictWeakOrdering 's argument type.

Preconditions

For the first version:

• [first, last) is a valid range.

• [first, last – 1) is a valid range. That is, [first, last) is nonempty.

• [first, last – 1) is a heap. That is, is_heap(first, last – 1) is true .

For the second version:

• [first, last) is a valid range.

• [first, last – 1) is a valid range. That is, [first, last) is nonempty.

• [first, last) is a heap. That is, is_heap(first, last – 1, comp) is true .

Читать дальше
Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Похожие книги на «Standard Template Library Programmer's Guide»

Представляем Вашему вниманию похожие книги на «Standard Template Library Programmer's Guide» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.


Отзывы о книге «Standard Template Library Programmer's Guide»

Обсуждение, отзывы о книге «Standard Template Library Programmer's Guide» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.

x