CosmicRaySort Atom Feed 0

In Brief Worst sorting algorithm... ever. It repeatedly checks if the array is sorted hoping that cosmic rays will change the numbers enough for them to appear in order.... more
Implementation Difficulty * * * * *
 1 function cosmic_ray_sort(array)
2
3 while(check_whether_sorted(array) == false)
4 // Hope a cosmic ray flips some bits in the array
5 end while
6
7 end function
8
9 function check_whether_sorted(array)
10
11 n = length(array)
12
13 for i = 1 to i = n-1
14
15 // If any two consecutive values are out of order
16 // then the array is not sorted.
17 if array[i] > array[i + 1]
18 return False
19 end if
20
21 end for
22
23 // If nothing was out of order, the array is sorted.
24 return True
25
26 end function
Flow Graph

Worst sorting algorithm... ever. It repeatedly checks if the array is sorted hoping that cosmic rays will change the numbers enough for them to appear in order.

Warning

Please don't implement this algorithm.