Radix Sort

Code Id 30
Date Updated 3/7/2010
Title Radix sort  
Description
The radix sort is based on the positional value of the actual digits of the numbers being sorted.  
                                  
Codes Snippet
radix_sort(rec,n)
struct {
        int info;
        int next;
        }rec[n];
int n;
{
        int f[10],r[10], first, i, j, k, p, q, y, e, m, first =0 ;
        for (k=1; k< 10; i++)
        {
                r[i] = f[i] = -1;
        }
        while (first != -1)
        {
                p = first;
        first = rec[first].next;
                y = rec[p].info;
                e = power(10, k �1);
                j = (y/e) % 10;
                q = r[j];
                if ( q == -1)
                        f[j] = p;
                else
                        rec[q].next = p;
                        r[j] = p;
                }
                /*combine all the queues to form a single list*/
                for (j=0; j<10 && f[j] == -1; j++) ; /*to find the first element*/
                first = f[j];
                while ( j<=9)
                {
                        for ( i= j+1; i < 10 && f[j] == -1; i++);
                        if ( i <= 9)
                        {
                                p = i;
                                rec [ r[j]].next = f[i];
                        }
                        j = i ;
                }
        rec [ r[p]].next = -1;
}

Comments are closed.