home | login | register | DMCA | contacts | help | donate |      

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z


my bookshelf | genres | recommend | rating of books | rating of authors | reviews | new | | collections | | | add
fantasy
space fantasy
fantasy is horrors
heroic
prose
  military
  child
  russian
detective
  action
  child
  ironical
  historical
  political
western
adventure
adventure (child)
child's stories
love
religion
antique
Scientific literature
biography
business
home pets
animals
art
history
computers
linguistics
mathematics
religion
home_garden
sport
technique
publicism
philosophy
chemistry
close

Loading...


Example

bool eq_nosign(int x, int y) { return abs(x) == abs(y); }


void lookup(int* first, int* last, size_t count, int val) {

cout << "Searching for a sequence of " << count << " '" << val << "'" << (count != 1 ? "s: " : ": ");

int* result = search_n(first, last, count, val);

if (result == last) cout << "Not found" << endl;

else cout << "Index = " << result first << endl;

}


void lookup_nosign(int* first, int* last, size_t count, int val) {

cout << "Searching for a (sign-insensitive) sequence of " << count << " '" << val << "'" << (count != 1 ? "s: " : ": ");

int* result = search_n(first, last, count, val, eq_nosign);

if (result == last) cout << "Not found" << endl;

else cout << "Index = " << result first << endl;

}


int main() {

const int N = 10;

int A[N] = {1, 2, 1, 1, 3, 3, 1, 1, 1, 1};

lookup(A, A+N, 1, 4);

lookup(A, A+N, 0, 4);

lookup(A, A+N, 1, 1);

lookup(A, A+N, 2, 1);

lookup(A, A+N, 3, 1);

lookup(A, A+N, 4, 1);

lookup(A, A+N, 1, 3);

lookup(A, A+N, 2, 3);

lookup_nosign(A, A+N, 1, 3);

lookup_nosign(A, A+N, 2, 3);

}

The output is

Searching for a sequence of 1 '4': Not found

Searching for a sequence of 0 '4's: Index = 0

Searching for a sequence of 1 '1': Index = 0

Searching for a sequence of 2 '1's: Index = 2

Searching for a sequence of 3 '1's: Index = 6

Searching for a sequence of 4 '1's: Index = 6

Searching for a sequence of 1 '3': Index = 4

Searching for a sequence of 2 '3's: Not found

Searching for a (sign-insensitive) sequence of 1 '3': Index = 4

Searching for a (sign-insensitive) sequence of 2 '3's: Index = 4


Complexity | Standard Template Library Programmer`s Guide | Notes







Loading...