hamzajaved

Radix Sort

Oct 20th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.75 KB | None | 0 0
  1. class Program
  2.     {
  3.         static void Main(string[] args)
  4.         {
  5.             int[] a = {20,24,235,269,298,457,11,15,5555,8789,45,03,8987,444,44,005,04,02,877897,545454 };
  6.             int[] c = new int[a.Length];
  7.             int d = a.Max();
  8.             int t =10;
  9.             int u = 10;
  10.  
  11.             while (d != 0)
  12.             {
  13.               d= d / 10;
  14.                 t=t*10 ;
  15.             }
  16.             while (u <= t)
  17.             {
  18.                
  19.                 int x, y;
  20.                 for (int i = 0; i < a.Length; i++)
  21.                 {
  22.                     c[i] = a[i] % u;
  23.                 }
  24.                 for (int k = 0; k < a.Length; k++)
  25.                 {
  26.                     for (int j = 0; j < a.Length; j++)
  27.                     {
  28.                         if (c[k] <= c[j])
  29.                         {
  30.                             x = c[k];
  31.                             c[k] = c[j];
  32.                             c[j] = x;
  33.                         }
  34.                     }
  35.                 }
  36.                 for (int l = 0; l < a.Length; l++)
  37.                 {
  38.                     for (int m = 0; m < a.Length; m++)
  39.                     {
  40.                         if ((a[l] % u) == c[m])
  41.                         {
  42.                             y = c[m];
  43.                             c[m] = a[l];
  44.                             a[l] = y;
  45.                         }
  46.                     }
  47.                 }
  48.                 int e = 0;
  49.                 foreach (int item in c)
  50.                 {
  51.                     a[e] = item;
  52.                     e++;
  53.                 }
  54.  
  55.                 u = u * 10;
  56.             }
  57.             foreach (int item in a)
  58.             {
  59.  
  60.                 Console.WriteLine(item);
  61.             }
  62.         }
  63.     }
Add Comment
Please, Sign In to add comment