Sort Array using LSD Radix Sort
Write a C Program to Sort Array using LSD Radix Sort. Here’s simple Program to Sort Array using LSD Radix Sort in C Programming Language.
Below is the source code for C Program to Sort Array using LSD Radix Sort which is successfully compiled and run on Windows System to produce desired output as shown below :
SOURCE CODE : :
/* C Program to Sort Array using LSD Radix Sort */ #include <stdio.h> int min = 0, count = 0, array[100] = {0}, array1[100] = {0}; void main() { int k, i, j, temp, t, n; printf("Enter size of array :"); scanf("%d", &count); printf("Enter elements into array :"); for (i = 0; i < count; i++) { scanf("%d", &array[i]); array1[i] = array[i]; } for (k = 0; k < 3; k++) { for (i = 0; i < count; i++) { min = array[i] % 10; /* To find minimum lsd */ t = i; for (j = i + 1; j < count; j++) { if (min > (array[j] % 10)) { min = array[j] % 10; t = j; } } temp = array1[t]; array1[t] = array1[i]; array1[i] = temp; temp = array[t]; array[t] = array[i]; array[i] = temp; } for (j = 0; j < count; j++) /*to find MSB */ array[j] = array[j] / 10; } printf("Sorted Array (lSd radix sort) : "); for (i = 0; i < count; i++) printf("%d ", array1[i]); }
Output :
/* C Program to Sort Array using LSD Radix Sort */ Enter size of array :7 Enter elements into array :22 64 121 78 159 206 348 Sorted Array (lsd radix sort) : 22 64 78 159 121 206 348
Above is the source code for C Program to Sort Array using LSD Radix Sort which is successfully compiled and run on Windows System.The Output of the program is shown above .
If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach up to you in short interval.
Thanks for reading the post….