SkyHawk

Bogo Sort

Jul 6th, 2011
408
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdlib.h>
  2. #define FOR(i,n) for(int i = 0;i < n;++i)
  3.  
  4. void bogoSort(int* p,int l)
  5. {
  6.     bool sorted = true;
  7.     int t,j;
  8.     FOR(i,l-1)
  9.         if(!(sorted = p[i]<p[i+1]))
  10.             break;
  11.     while(!sorted)
  12.     {
  13.         FOR(i,l)
  14.         {
  15.             j = rand()%l;
  16.             t = p[i];
  17.             p[i] = p[j];
  18.             p[j] = t;
  19.         }  
  20.         sorted = true;
  21.         FOR(i,l-1)
  22.             if(!(sorted = p[i]<p[i+1]))
  23.                 break;
  24.     }
  25. }
RAW Paste Data