CPP   87
generic sort algorithm
Guest on 3rd February 2023 01:42:57 AM


  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cassert>
  4. using namespace std;
  5.  
  6. int main() {
  7.   cout << "Using an in-place generic sort algorithm." << endl;
  8.   int a[1000];
  9.   int i;
  10.   for (i = 0; i < 1000; ++i)
  11.     a[i] = 1000 - i - 1;
  12.  
  13.   sort(&a[0], &a[1000]);
  14.  
  15.   for (i = 0; i < 1000; ++i)
  16.     assert (a[i] == i);
  17.   cout << " --- Ok." << endl;
  18.   return 0;
  19. }

Raw Paste

Login or Register to edit or fork this paste. It's free.