Sorting algorithms/Bogosort: Difference between revisions

Content added Content deleted
Line 1,852:
 
=={{header|Swift}}==
<lang swift>funcimport shuffle<T>(array: T[]) {Darwin
 
for i in 1..array.count {
func shuffle<T>(inout array: [T]) {
let j = Int(arc4random_uniform(UInt32(i)))
for (array[i], array[j])in = (1..<array[j],.count array[i]){
let j = Int(arc4random_uniform(UInt32(i)))
}
(array[i], array[j]) = (array[j], array[i])
}
}
 
func issorted<T:Comparable>(ary: T[T]) -> Bool {
for i in 1..<(ary.count-1) {
if ary[i] > ary[i+1] {
return false
}
}
}
return true
}
 
func bogosort<T:Comparable>(inout ary: T[T]) {
while !issorted(ary) {
shuffle(&ary)
}
}</lang>