Professional Documents
Culture Documents
Radix Sort
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. eys may be a string of characters! or numerical digits in a given "radix". #he 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). #he se$uence in which digits are processed by a LSD radix sort is the opposite of the se$uence in which digits are processed by a most significant digit (%SD) radix sort. An LSD radix sort operates in &(nk) time! where n is the number of keys! and k is the average key length. #his 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 +&,-# ./ int main() 0 int a1+&,-#23 int temp1+&,-#23 int i!max4/!x4.!si5e!54.3 clrscr()3 printf(67nter #he Si5e of the Array6)3 scanf(6:d6!;si5e)3 printf(67nter the Array 7lements<n6)3 for(i4/3i)si5e3i==) scanf(6:d6!;a1i2)3 printf(6#he >ou 7ntered is As ?<n6)3 for(i4/3i)si5e3i==) printf(6:Ad<t6!a1i2)3 for(i4/3i)si5e3i==) 0 if(a1i2*max) max4a1i23 E while(max85*/) 0 int buck1./240 / E3 for(i4/3i)si5e3i==) buck1((a1i28x)85):./2==3 for(i4.3i)G3i==) buck1i2=4buck1i'.23
for(i4/3i)si5e3i'') 88Sorting Fased &n Hositions temp1''buck1((a1i28x)85):./224a1i23 printf(6<nHASS ?<t6)3 for(i4/3i)si5e3i==) 0 a1i24temp1i23 printf(6:Ad<t6!a1i2)3 E x84./3 5I4./3 E printf(6<n#he Sotred Array Ds As ?<n6)3 for(i4/3i)si5e3i==) printf(6:Ad<t6!a1i2)3 getch()3 return(/)3 E 88%aking &riginal Array with sort