Introduction
Prerequisites: Miracles, Sense of Humour
Miracle sort is a sort that truly requires a miracle. We keep checking the array until it is sorted. It requires that some external force (a miracle?) changes some bits in the computer in a way that it becomes sorted.
Implementation
We keep checking if the array is sorted until some miracle occurs.
Code
public void miracleSort(int[] arr) { boolean sorted = false; do { sorted = true; for (int i = 1; i < arr.length; i++) { if (arr[i] < arr[i - 1]) { sorted = false; break; } } } while (!sorted); }