Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.66 KB | None | 0 0
  1. public static void CountingSort(DataList items)
  2.         {
  3.             int multi = 1000000;
  4.             double max = (int)(items.Head() * multi);
  5.             double temp = (int)(items.Head() * multi);
  6.             for (int i = 0; i < items.Length - 1; i++)
  7.             {
  8.                 if (temp > max)
  9.                     max = temp;
  10.                 temp = (int)(items.Next() * multi);
  11.                 opMcout = opMcout + 4;
  12.             }
  13.  
  14.             int[] counts = new int[(int)max + 1];
  15.  
  16.  
  17.             temp = (int)(items.Head() * multi);
  18.             for (int i = 0; i < items.Length - 1; i++)
  19.             {
  20.                 counts[(int)temp]++;
  21.                 temp = (int)(items.Next() * multi);
  22.             }
  23.             opMcout = opMcout + 3;
  24.  
  25.             int j = items.Length - 1;
  26.             int c = 1;
  27.             double current, previous;
  28.             for (int i = counts.Length - 1; i >= 0; i--)
  29.             {
  30.                 current = (int)(items.Head() * multi);
  31.                 previous = current;
  32.                 current = (int)(items.Next() * multi);
  33.                 while (counts[i] > 0)
  34.                 {
  35.                     while (c <= j)
  36.                     {
  37.                         if (previous == i)
  38.                         {
  39.                             while (c != j)
  40.                             {
  41.                                 items.Swap((Convert.ToDouble(current) / multi), (Convert.ToDouble(previous) / multi));
  42.                                 current = (int)(items.Next() * multi);
  43.                                 c++;
  44.                                 opMcout = opMcout + 1;
  45.                             }
  46.                             if (current < previous)
  47.                             {
  48.                                 items.Swap((Convert.ToDouble(current) / multi), (Convert.ToDouble(previous) / multi));
  49.                             }
  50.                             opMcout = opMcout + 2;
  51.                         }
  52.                         else
  53.                         {
  54.                             previous = current;
  55.                             current = (int)(items.Next() * multi);
  56.                             opMcout = opMcout + 2;
  57.                         }
  58.                         opMcout = opMcout + 2;
  59.                         c++;
  60.                     }
  61.                     j--;
  62.                     counts[i]--;
  63.                     current = (int)(items.Head() * multi);
  64.                     previous = current;
  65.                     current = (int)(items.Next() * multi);
  66.                     c = 1;
  67.                     opMcout = opMcout + 3;
  68.                 }
  69.                 opMcout = opMcout + 5;
  70.             }
  71.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement