commit deletes
This commit is contained in:
parent
776bba907c
commit
372c577f83
233 changed files with 0 additions and 6724 deletions
|
|
@ -1,24 +0,0 @@
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class Bogosort {
|
||||
private static <T extends Comparable<? super T>> boolean isSorted(List<T> list) {
|
||||
if (list.isEmpty())
|
||||
return true;
|
||||
Iterator<T> it = list.iterator();
|
||||
T last = it.next();
|
||||
while (it.hasNext()) {
|
||||
T current = it.next();
|
||||
if (last.compareTo(current) > 0)
|
||||
return false;
|
||||
last = current;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static <T extends Comparable<? super T>> void bogoSort(List<T> list) {
|
||||
while (!isSorted(list))
|
||||
Collections.shuffle(list);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue