Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace RadixSort
  8. {
  9.     class Program
  10.     {
  11.         List<int> unSortedList = new List<int>  {12,23,42,43,11,67,98,22,09,76,33,08,23,59,37,28,90,84,62,44,3,91,36,77,87,8,00,23};
  12.         Queue<int>[] buckets=new Queue<int>[10];
  13.         int modulo = 10;
  14.         List<int> workSet = new List<int>();
  15.         List<int> sortedList = new List<int>();
  16.         int passesCompleted = 0;
  17.  
  18.         public void sort(){
  19.             while (unSortedList.Count > 0){
  20.                 foreach (int ele in unSortedList){
  21.                     bool elePlacedInBucket = false;
  22.                     int bucket = ele % modulo;
  23.                     while (!elePlacedInBucket){
  24.                         if ((10 - bucket) > 0){
  25.                             if(buckets[bucket] == null)
  26.                                 buckets[bucket]=new Queue<int>();
  27.                             buckets[bucket].Enqueue(ele);
  28.                             elePlacedInBucket = true;
  29.                         }
  30.                         else{
  31.                             bucket = (bucket - (bucket % 10))/10;
  32.                         }
  33.                     }                                      
  34.                 }
  35.      
  36.                 foreach (Queue<int> q in buckets){
  37.                     if (q != null){
  38.                         while (q.Count > 0){
  39.                             var ele = q.Dequeue();
  40.                             if ((modulo - ele) > 0)
  41.                                 this.sortedList.Add(ele);                            
  42.                             else
  43.                                 this.workSet.Add(ele);                            
  44.                         }
  45.                     }
  46.                 }
  47.  
  48.                 modulo = modulo * 10;
  49.                 unSortedList = workSet.ConvertAll<int>((i)=>i);
  50.                 workSet.Clear();
  51.                 passesCompleted += 1;
  52.             }
  53.         }
  54.        
  55.         static void Main(string[] args)
  56.         {
  57.             Program p = new Program();
  58.             p.sort();
  59.             foreach (int ele in p.sortedList){
  60.                 Console.WriteLine(ele + " ");
  61.             }
  62.             Console.ReadKey();
  63.         }
  64.     }
  65. }