Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void CountingSort(DataList items)
- {
- int multi = 1000000;
- double max = (int)(items.Head() * multi);
- double temp = (int)(items.Head() * multi);
- for (int i = 0; i < items.Length - 1; i++)
- {
- if (temp > max)
- max = temp;
- temp = (int)(items.Next() * multi);
- opMcout = opMcout + 4;
- }
- int[] counts = new int[(int)max + 1];
- temp = (int)(items.Head() * multi);
- for (int i = 0; i < items.Length - 1; i++)
- {
- counts[(int)temp]++;
- temp = (int)(items.Next() * multi);
- }
- opMcout = opMcout + 3;
- int j = items.Length - 1;
- int c = 1;
- double current, previous;
- for (int i = counts.Length - 1; i >= 0; i--)
- {
- current = (int)(items.Head() * multi);
- previous = current;
- current = (int)(items.Next() * multi);
- while (counts[i] > 0)
- {
- while (c <= j)
- {
- if (previous == i)
- {
- while (c != j)
- {
- items.Swap((Convert.ToDouble(current) / multi), (Convert.ToDouble(previous) / multi));
- current = (int)(items.Next() * multi);
- c++;
- opMcout = opMcout + 1;
- }
- if (current < previous)
- {
- items.Swap((Convert.ToDouble(current) / multi), (Convert.ToDouble(previous) / multi));
- }
- opMcout = opMcout + 2;
- }
- else
- {
- previous = current;
- current = (int)(items.Next() * multi);
- opMcout = opMcout + 2;
- }
- opMcout = opMcout + 2;
- c++;
- }
- j--;
- counts[i]--;
- current = (int)(items.Head() * multi);
- previous = current;
- current = (int)(items.Next() * multi);
- c = 1;
- opMcout = opMcout + 3;
- }
- opMcout = opMcout + 5;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement