Skip to content

Instantly share code, notes, and snippets.

@plioi
Created September 14, 2013 20:27
Show Gist options
  • Save plioi/6565370 to your computer and use it in GitHub Desktop.
Save plioi/6565370 to your computer and use it in GitHub Desktop.
//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