Skip to content

Instantly share code, notes, and snippets.

Created April 16, 2013 04:50
Show Gist options
  • Save anonymous/5393438 to your computer and use it in GitHub Desktop.
Save anonymous/5393438 to your computer and use it in GitHub Desktop.
Close algorithm
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BucketSort
{
class Program
{
int[] listToBeSorted = new int[10];
public int decimalPlace;
int maximumValue = 100;
public void sort()
{
int numPasses = Math.Ceiling( Math.Log10( maximumValue ) );
foreach (decimalPlace <= maximumValue)
{
SortPass( listToBeSorted, decimalPlace )
}
public static SortPass( listToBeSorted, decimalPlace )
{
List<int> buckets = new List<10>;
foreach (bucket in buckets){
int bucketNum = GetDigit(var, decimalPlace);
buckets[bucketNum].Add(var);
}
int offset = 0;
foreach (bucket in buckets)
{
bucket.copyTo(listToBeSorted, offset);
offset += bucket.Count;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment