using System; using System.Collections.Generic; namespace BucketSort { public class BucketSort { static void Main(string[] args) { // our list int[] x = new int[] { 99, 95, 90, 85, 80, 75, 70, 65, 60, 55, 50, 45, 40, 35, 30, 25, 20, 15, 10, 5, 1 }; // sort list List<int> sorted = Run_Sort(x); // build list foreach (int i in sorted) // show list Console.WriteLine(i); Console.Read(); } public static List<int> Run_Sort(params int[] x) { List<int> result = new List<int>(); int numOfBuckets = 10; List<int>[] buckets = new List<int>[numOfBuckets]; for (int i = 0; i < numOfBuckets; i++) buckets[i] = new List<int>(); for (int i = 0; i < x.Length; i++) { int buckitChoice = (x[i] / numOfBuckets); buckets[buckitChoice].Add(x[i]); } for (int i = 0; i < numOfBuckets; i++) { int[] temp = BubbleSortList(buckets[i]); result.AddRange(temp); } return result; } public static int[] BubbleSortList(List<int> input) { for (int i = 0; i < input.Count; i++) { for (int j = 0; j < input.Count; j++) { if (input[i] < input[j]) { int temp = input[i]; input[i] = input[j]; input[j] = temp; } } } return input.ToArray(); } } }