예제 #1
0
        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);
                }
            }
        }
예제 #2
0
        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++;
                    }
                }
            }
        }
예제 #3
0
        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++;
                }
            }
        }
예제 #4
0
        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]);
                }
            }
        }