Can this be cleaned up?
using System;
class AscendingBubbleSort
{
public static void Main()
{
int i = 0,j = 0,t = 0;
int []c=
I believe there is an improvement in the answer proposed by Jon Skeet. After each loop, the number of iterations should exclude the last item processed in the previous iteration. So, here's the code:
public void BubbleSortImproved(IList list)
{
BubbleSortImproved(list, Comparer.Default);
}
public void BubbleSortImproved(IList list, IComparer comparer)
{
bool stillGoing = true;
int k = 0;
while (stillGoing)
{
stillGoing = false;
//reduce the iterations number after each loop
for (int i = 0; i < list.Count - 1 - k; 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;
}
}
k++;
}
}