beautypg.com

HP Integrity NonStop H-Series User Manual

Page 180

background image

set_union

form union of two sets

set_intersection

form intersection of two sets

set_difference

form difference of two sets

set_symmetric_difference

form symmetric difference of two sets

includes

see if one set is a subset of another

Heap operations
Section

Heap Operations

make_heap

turn a sequence into a heap

push_heap

add a new value to the heap

pop_heap

remove largest value from the heap

sort_heap

turn heap into sorted collection

Ordered collections can be created using the standard library in a variety of ways. For example:

The containers

set

,

multiset

,

map

and

multimap

are ordered collections by definition.

A

list

can be ordered by invoking the sort() member function.

A

vector

,

deque

or ordinary C++ array can be ordered by using one of the sorting algorithms

described later in this section.

Like the generic algorithms described in the previous section, the algorithms described here are
not specific to any particular container class. This means they can be used with a wide variety
of types. Many of them do, however, require the use of random-access iterators. For this reason
they are most easily used with vectors, deques, or ordinary arrays.

Obtaining the Sample Programs

Almost all the algorithms described in this section have two versions. The first version uses the
less than operator (operator <) for comparisons appropriate to the container element type. The
second, and more general, version uses an explicit comparison function object, which we will
write as Compare. This function object must be a binary predicate (see

Section 3: Sorting

Algorithms

). Since this argument is optional, we will write it within square brackets in the

description of the argument types.

A sequence is considered to be ordered if for every valid (that is, denotable) iterator i with a
denotable successor j, it is the case that the comparison Compare(*j, *i) is false. Note that this
does not necessarily imply that Compare(*i, *j) is true. It is assumed that the relation imposed
by Compare is transitive, and induces a total ordering on the values.

In the descriptions that follow, two values x and y are said to be equivalent if both Compare(x,

This manual is related to the following products: