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

This example uses next_permutation to implement the worst known deterministic sorting algorithm. Most sorting algorithms are O(N log(N)), and even bubble sort is only O(N^2) . This algorithm is actually O(N!).

template

void snail_sort(BidirectionalIterator first, BidirectionalIterator last) {

 while (next_permutation(first, last)) {};

}


int main() {

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

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

 snail_sort(A, A+N);

 copy (A, A+N, ostream_iterator(cout, "\n"));

}


Preconditions | Standard Template Library Programmer`s Guide | Notes







Loading...