You are on page 1of 2

Radix Sort

A least significant digit (LSD) radix sort is a fast stablev sorting algorithm which can be used to sort keys in integer representation order. Keys may be a string of characters, or numerical digits in a given 'radix'. The processing of the keys begins at the least significant digit (i.e., the rightmost digit), and proceeds to the most significant digit (i.e., the leftmost digit). The sequence in which digits are processed by a LSD radix sort is the opposite of the sequence in which digits are processed by a most significant digit (MSD) radix sort. An LSD radix sort operates in O(nk) time, where n is the number of keys, and k is the average key length. This kind of performance for variable-length keys can be achieved by grouping all of the keys that have the same length together and separately performing an LSD radix sort on each group of keys for each length, from shortest to longest, in order to avoid processing the whole list of keys on every sorting pass. Program: #include<stdio.h> #include<conio.h> #define COUNT 10 int main() { int a[COUNT]; int temp[COUNT]; int i,max=0,x=1,size,z=1; clrscr(); printf("Enter The Size of the Array"); scanf("%d",&size); printf("Enter the Array Elements\n"); for(i=0;i<size;i++) scanf("%d",&a[i]); printf("The You Entered is As :\n"); for(i=0;i<size;i++) printf("%3d\t",a[i]); for(i=0;i<size;i++) { if(a[i]>max) max=a[i]; } while(max/z>0) { int buck[10]={ 0 }; for(i=0;i<size;i++) buck[((a[i]/x)/z)%10]++; for(i=1;i<9;i++) buck[i]+=buck[i-1];

//Reading Array Size //Reading Array Elements

//Display the Unsorted_Array

//Finding the Max Value In Array

//Filling the Bucket with Count //Setting Positions with Bucket

for(i=0;i<size;i--) //Sorting Based On Positions temp[--buck[((a[i]/x)/z)%10]]=a[i]; printf("\nPASS :\t"); for(i=0;i<size;i++) { a[i]=temp[i]; printf("%3d\t",a[i]); } x/=10; z*=10; } printf("\nThe Sotred Array Is As :\n"); for(i=0;i<size;i++) printf("%3d\t",a[i]); getch(); return(0); } //Making Original Array with sort

//Moving to the next Position

//Display the Sorted_Array

You might also like