System . out . println ( "List is sorted above in " + count + " tries!" );

"How many elements would you like to sort?"

System . out . println ( "How many elements would you like to sort?" );

So, I made this out of inspiration for some of the students in a lower level CS class. They were talking about sorting algorithms and wanted to know one that could work in the best possible time. Introduce bogo sort! While it relies on this nasty thing called probability and its Worse case is O(forever), it 'could' solve it on the first try. Enjoy.

If you want it to go faster, comment out the print statements in the while loop.

Example of output, number entered being ten.

5616773: 2 1 4 5 6 3 7 8 9 0

5616774: 9 5 6 2 4 1 3 8 0 7

5616775: 8 2 5 1 9 3 7 4 6 0

5616776: 6 7 0 2 1 5 3 4 8 9

5616777: 3 1 5 8 6 4 9 0 7 2

5616778: 5 6 7 8 2 1 3 4 0 9

5616779: 0 1 2 3 4 5 6 7 8 9

List is sorted above in 5616780 tries!