Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #if defined _bogo_sort_included
- #endinput
- #endif
- #define _bogo_sort_included
- #pragma library BogoSort
- stock BogoShuffle(array[], const len = sizeof array)
- {
- for(new i = 0; i < len - 1; i++)
- {
- new tmpValue = array[i];
- new rand = random(len);
- array[i] = array[rand];
- array[rand] = tmpValue;
- }
- shuffleTry++;
- }
- stock BogoIsSorted(const array[], const len = sizeof array)
- {
- for (new i = 0; i < len -1; i++)
- {
- if (array[i] > array[i + 1])
- return 0;
- }
- return 1;
- }
- stock BogoSort(array[], const len = sizeof array)
- {
- shuffleTry = 0;
- bogoStart = GetTickCount();
- while(!BogoIsSorted(array, len))
- {
- BogoShuffle(array, len);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement