Skip to content

Instantly share code, notes, and snippets.

@danielcrenna
Created December 15, 2012 05:24
Show Gist options
  • Save danielcrenna/4291510 to your computer and use it in GitHub Desktop.
Save danielcrenna/4291510 to your computer and use it in GitHub Desktop.
An implementation of bubble sort in C#.
using System.Collections.Generic;
public class BubbleSort
{
public void Sort<T>(IList<T> items)
{
var due = true;
while(due)
{
due = false;
for (var i = 0; i < items.Count; i++)
{
if (i + 1 >= items.Count)
{
continue;
}
var left = items[i].GetHashCode();
var right = items[i + 1].GetHashCode();
if (left <= right)
{
continue;
}
var temp = items[i];
items[i] = items[i + 1];
items[i + 1] = temp;
due = true;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment