- #1
SlurrerOfSpeech
- 141
- 11
Let me know if I've invented a valid O(n) sorting algorithm.
Code:
public void Sort ( this List<T> L )
{
// Check every second whether L is sorted
// Given enough time, natural bit flips will eventually make L sorted
while ( !L.IsSorted() ) Thread.Sleep(1000);
}
public bool IsSorted ( this List<T> L )
{
// Returns true or false depending on whether L is in ascending order
for ( int i = 1, n = L.Length; i < n; ++i ) if ( L[i-1] > L[i] ) return false;
return true;
}