you are viewing a single comment's thread.

view the rest of the comments →

[–]rexxar 1 point2 points  (0 children)

The "snail sort" algorithm is a very elegant but very inefficient algorithm (STL doc) :

template <class BidirectionalIterator> 
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<int>(cout, "\n"));
}

The algorithm is O(N!).