Advertisement
Guest User

Untitled

a guest
Oct 24th, 2024
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 0.75 KB | Source Code | 0 0
  1. #if defined _bogo_sort_included
  2.   #endinput
  3. #endif
  4. #define _bogo_sort_included
  5. #pragma library BogoSort
  6.  
  7. stock BogoShuffle(array[], const len = sizeof array)
  8. {
  9.     for(new i = 0; i < len - 1; i++)
  10.     {
  11.         new tmpValue = array[i];
  12.         new rand = random(len);
  13.         array[i] = array[rand];
  14.         array[rand] = tmpValue;
  15.     }
  16.     shuffleTry++;
  17. }
  18.  
  19. stock BogoIsSorted(const array[], const len = sizeof array)
  20. {
  21.     for (new i = 0; i < len -1; i++)
  22.     {
  23.         if (array[i] > array[i + 1])
  24.             return 0;
  25.     }
  26.     return 1;
  27. }
  28.  
  29. stock BogoSort(array[], const len = sizeof array)
  30. {
  31.     shuffleTry = 0;
  32.     bogoStart = GetTickCount();
  33.     while(!BogoIsSorted(array, len))
  34.     {
  35.         BogoShuffle(array, len);
  36.     }
  37. }
Tags: SA-MP
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement