Sort in descending order

How do I implement this sorting algorithm in descending order without using vector library or std::reverse? I tried to change the signs using trial and error but it's either my program crashed or the sort was not working at all. I was comparing the process time of some sorting algorithms.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
  void radixSort(int *a, int arraySize)
{
int i, bucket[arraySize]; //Using c++ VLA extension
int maxVal = 0;
int digitPosition =1;
	for(i = 0; i < arraySize; i++)
	{
		if(a[i] > maxVal)
            maxVal = a[i];
	}

	int pass = 1;  // used to show the progress
	/* maxVal: this variable decide the while-loop count
	           if maxVal is 3 digits, then we loop through 3 times */
	while(maxVal/digitPosition > 0) {
		/* reset counter */
		int digitCount[10] = {0};

		/* count pos-th digits (keys) */
		for(i = 0; i < arraySize; i++)
			digitCount[a[i]/digitPosition%10]++;

		/* accumulated count */
		for(i = 1; i < 10; i++)
			digitCount[i] += digitCount[i-1];

		/* To keep the order, start from back side */
		for(i = arraySize - 1; i >= 0; i--)
			bucket[--digitCount[a[i]/digitPosition%10]] = a[i];

		/* rearrange the original array using elements in the bucket */
		for(i = 0; i < arraySize; i++)
			a[i] = bucket[i];
		/* move up the digit position */
		digitPosition *= 10;
	}
 }


Any help will be gladly appreciated
I don't know what your function does, but isn't the principle of radix-sort to distribute input into bins in such manner that when you read the bins in order, you get a sorted output? If so, the data in the bins is sorted (ascending) and you simply need to read the bins in reverse order to get the descending output.
Unfortunately, I do not know how to understand the radix sort because I'm just a beginner in c++ and I am only comparing the time complexity of sorting algorithms. I only knew how to do the bubble, selection, and bucket sort.
If you don't understand an algorithm, then you cannot implement it efficiently, and then performance comparisons are unreliable, aren't they?

Algorithms are abstract, language-independent logic. The different sorts are described (somewhere). How to write the logic in language X is semi-separate issue.
Topic archived. No new replies allowed.