course.wilkes.edu/CS125Labs
Welcome to the site for CS 125 labs!

 

standard C++ algorithms.

Prev | Next | Lab 9

In each of the following descriptions, start is an iterator pointing to the beginning of a sequence (usually container.begin()), and stop is an iterator pointing to the end of a sequence (usually container.end()). Most of these require that the header file algorithm be included (accumulate() requires numeric instead). This is not an exhaustive listing of the C++ standard algorithms library. For an exhaustive list, see the latest on the ANSI C++ standard at Cygnus.com.

algorithmDescription
accumulate(start, stop, value); Return the sum of the values in the sequence plus value
find(start, stop, value); Return an iterator to value in the sequence, or stop if it is not present
count(start, stop, value); Return the number of times value occurs in the sequence
fill(start, stop, value); Assign value to every element of the sequence
iota(start, stop, value); Fill the sequence with monotonically ascending values, beginning with value
replace(start, stop, old, new); Replace each occurrence of old in the sequence with new
for_each(start, stop, F); Apply function F to each value in the sequence
max_element(start, stop); Return an iterator to the maximum value in the sequence
min_element(start, stop); Return an iterator to the minimum value in the sequence
reverse(start, stop); Reverse the order of the values in the sequence
random_shuffle(start, stop); Shuffle the values in the sequence randomly
sort(start, stop); Arrange the sequence's values in ascending order
binary_search(start, stop, value); Return true if value is in the sorted sequence, or false if it is not present
lower_bound(start, stop, value); Return an iterator to the first position at which value can be inserted, such that the sequence remains sorted.
upper_bound(start, stop, value); Return an iterator to the last position at which value can be inserted, such that the sequence remains sorted.
unique(start, stop); In the sequence, replace any consecutive occurrences of the same value with one instance of that value
next_permutation(start, stop); Shuffle the sequence to its next permutation and return true (If there is none, return false)
prev_permutation(start, stop); Shuffle the sequence to its previous permutation and return true (If there is none, return false)

Prev | Next | Lab 9

 
  Home

Help

Lab 0

Lab 1

Lab 2

Lab 3a

Lab 3b

Lab 4

Lab 5

Lab 6

Lab 7

Lab 8

Lab 9

Lab 10

Lab 11

Lab 12

Lab 13



Membership

Login




Last update: Friday, August 25, 2000 at 9:31:29 AM.
visitors to this page.