Created
December 15, 2012 05:24
-
-
Save danielcrenna/4291510 to your computer and use it in GitHub Desktop.
An implementation of bubble sort in C#.
This file contains 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
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