diff --git a/RADIX_SORT IN C++ b/RADIX_SORT IN C++ new file mode 100644 index 00000000..7562c8fd --- /dev/null +++ b/RADIX_SORT IN C++ @@ -0,0 +1,82 @@ +//IMPLEMENTING RADIX SORT IN C++ +//INCLUDING HEADER FILES +#include +#include +#include + +using namespace std; + +//Getmax FUNCTION CODE TO GET +//THE MAXIMUM NUMBER FROM THE ARRAY +int Getmax(int *array,int n) +{ + int max=array[0]; + for(int z=1;zmax) + max=array[z]; + } + return max; +} +//count_sort FUNCTION TO PERFORM THE COUNT SORT +void count_sort(int *arr,int n,int exp) +{ + int output[n]; + int i; + int count[10] + //initializing count array with 0. + for(i=0;i<10;i++) + { + count[i]=0; + } + for(i=0;i=0;i--) + { + //assigning the output array with the + //sorted array. + output[count[(arr[i]/exp)%10]-1]=arr[i]; + count[(arr[i]/exp)%10]--; + } + for(i=0;i0;exp=exp*10) + { + //repeated count sort till the maximum + //place value is reached. + count_sort(arr,n,exp); + } + } +//main FUNCTION HERE +void main() +{ +clrscr(); +//here the integer array is limited that will become +//infinite later + int arr[5]={189,75,23,198,8}; + radix_sort(arr,5); + for(int j=0;j<5;j++) + { + cout<