private void SortBuckets(List <int>[] buckets) { var sorter = new Quicksorter <int>(); for (int i = 0; i < buckets.Length; i++) { List <int> currentBucket = buckets[i]; if (currentBucket != null) { sorter.Sort(currentBucket); } } }
public void Sort(List <int> collection) { var buckets = new List <int> [collection.Count]; // fill buckets foreach (var element in collection) { int bucketIndex = (int)(element / this.Max * collection.Count); if (buckets[bucketIndex] == null) { buckets[bucketIndex] = new List <int>(); } buckets[bucketIndex].Add(element); } //sort each bucket var sorted = new Quicksorter <int>(); for (int i = 0; i < buckets.Count(); i++) { if (buckets[i] != null) { sorted.Sort(buckets[i]); } } // copy the elements in the collection int index = 0; foreach (var bucket in buckets) { if (bucket != null) { foreach (var item in bucket) { collection[index] = item; index++; } } } }
public void Sort(List <int> collection) { var buckets = new List <int> [collection.Count]; foreach (var element in collection) { int bucketIndex = (int)(element / this.Max * collection.Count); if (buckets[bucketIndex] == null) { buckets[bucketIndex] = new List <int>(); } buckets[bucketIndex].Add(element); } var sorter = new Quicksorter <int>(); for (int i = 0; i < buckets.Length; i++) { if (buckets[i] != null) { sorter.Sort(buckets[i]); } } int index = 0; foreach (var bucket in buckets) { if (bucket == null) { continue; } foreach (var item in bucket) { collection[index] = item; index++; } } }
public void Sort(List <int> collection) { var buckets = new List <int> [collection.Count]; foreach (var element in collection) { int bucketIndex = (int)(element / this.Max * collection.Count); if (buckets[bucketIndex] == null) { buckets[bucketIndex] = new List <int>(); } buckets[bucketIndex].Add(element); } collection.Clear(); var sorter = new Quicksorter <int>(); for (int i = 0; i < buckets.Length; i++) { if (buckets[i] == null) { continue; } var bucketCollection = new SortableCollection <int>(buckets[i]); bucketCollection.Sort(sorter); } for (int i = 0; i < buckets.Length; i++) { if (buckets[i] != null) { buckets[i].Sort(); collection.AddRange(buckets[i]); } } }