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

partial_sort_copy , sort , stable_sort , binary_search , lower_bound , upper_bound , less , StrictWeakOrdering, LessThan Comparable

partial_sort_copy

Category: algorithms

Component type: function

Prototype

Partial_sort_copy is an overloaded name; there are actually two partial_sort_copy functions.

template

RandomAccessIterator partial_sort_copy(InputIterator first, InputIterator last, RandomAccessIterator result_first, RandomAccessIterator result_last);

template

RandomAccessIterator partial_sort_copy(InputIterator first, InputIterator last, RandomAccessIterator result_first, RandomAccessIterator result_last, Compare comp);

Description

Partial_sort_copy copies the smallest N elements from the range [first, last) to the range [result_first, result_first + N) , where N is the smaller of last – first and result_last – result_first . The elements in [result_first, result_first + N) will be in ascending order.

The two versions of partial_sort_copy 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 partial_sort_copy is as follows. If i and j are any two valid iterators in the range [result_first, result_first + N) such that i precedes j , then *j < *i will be false . The corresponding postcondition for the second version is that comp(*j, *i) will be false .

The return value is result_first + N .

Definition

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

Requirements on types

For the first version:

• InputIterator is a model of InputIterator.

• RandomAccessIterator is a model of Random Access Iterator.

• RandomAccessIterator is mutable.

• The value types of InputIterator and RandomAccessIterator are the same.

• RandomAccessIterator 's value type is LessThan Comparable.

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

For the second version:

• InputIterator is a model of InputIterator.

• RandomAccessIterator is a model of Random Access Iterator.

• RandomAccessIterator is mutable.

• The value types of InputIterator and RandomAccessIterator are the same.

• StrictWeakOrdering is a model of Strict Weak Ordering.

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

Preconditions

• [first, last) is a valid range.

• [result_first, result_last) is a valid range.

• [first, last) and [result_first, result_last) do not overlap.

Complexity

Approximately (last – first) * log(N) comparisons, where N is the smaller of last – first and result_last – result_first .

Example

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

const int N = sizeof(A) / sizeof(int);

vectorV(4);

partial_sort_copy(A, A + N, V.begin(), V.end());

copy(V.begin(), V.end(), ostream_iterator(cout, " "));

// The printed result is "1 2 3 4".

See also

partial_sort , sort , stable_sort , binary_search , lower_bound , upper_bound , less , StrictWeakOrdering, LessThan Comparable

is_sorted

Category: algorithms

Component type: function

Prototype

Is_sorted is an overloaded name; there are actually two is_sorted functions.

template

bool is_sorted(ForwardIterator first, ForwardIterator last)

template

bool is_sorted(ForwardIterator first, ForwardIterator last, StrictWeakOrdering comp)

Description

Is_sorted returns true if the range [first, last) is sorted in ascending order, and false otherwise.

The two versions of is_sorted 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 the function object comp . The first version of is_sorted returns true if and only if, for every iterator i in the range [first, last – 1) , *(i + 1) < *i is false . The second version returns true if and only if, for every iterator i in the range [first, last – 1) , comp(*(i + 1), *i) is false.

Definition

Defined in algo.h.

Requirements on types

For the first version:

• ForwardIterator is a model of Forward Iterator.

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

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

For the second version:

• ForwardIterator is a model of Forward Iterator.

• StrictWeakOrdering is a model of Strict Weak Ordering.

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

Preconditions

• [first, last) is a valid range.

Complexity

Linear. Zero comparisons if [first, last) is an empty range, otherwise at most (last – first) – 1 comparisons.

Example

int A[] = {1, 4, 2, 8, 5, 7};

const int N = sizeof(A) / sizeof(int);

assert(!is_sorted(A, A + N));

sort(A, A + N);

assert(is_sorted(A, A + N));

See also

sort , stable_sort , partial_sort , partial_sort_copy , sort_heap , binary_search , lower_bound , upper_bound , less , StrictWeakOrdering, LessThan Comparable

nth_element

Category: algorithms

Component type: function

Prototype

Nth_element is an overloaded name; there are actually two nth_element functions.

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

Интервал:

Закладка:

Сделать

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

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


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

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