Created
September 14, 2013 20:27
-
-
Save plioi/6565370 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Jon Skeet's Bubble Sort from http://stackoverflow.com/a/1595310 | |
public void BubbleSort<T>(IList<T> list, IComparer<T> comparer) | |
{ | |
bool stillGoing = true; | |
while (stillGoing) | |
{ | |
stillGoing = false; | |
for (int i = 0; i < list.Length-1; i++) | |
{ | |
T x = list[i]; | |
T y = list[i + 1]; | |
if (comparer.Compare(x, y) > 0) | |
{ | |
list[i] = y; | |
list[i + 1] = x; | |
stillGoing = true; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment