From 7acf4aa6a5847ff347ca577f6085ca6e4a4f68dc Mon Sep 17 00:00:00 2001 From: hariprasad2512 <111779312+hariprasad2512@users.noreply.github.com> Date: Sun, 30 Oct 2022 13:29:48 +0530 Subject: [PATCH] Create Radix_Sort.cpp --- Radix_Sort.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 Radix_Sort.cpp diff --git a/Radix_Sort.cpp b/Radix_Sort.cpp new file mode 100644 index 0000000..d521e82 --- /dev/null +++ b/Radix_Sort.cpp @@ -0,0 +1,61 @@ +#include +int maxElement(int arr[],int n){ + int max = arr[0]; + for(int i=1;imax){ + max = arr[i]; + } + } + return max; +} +void countSort(int a[],int n,int pos){ + int k=9; + int count[k+1]; + int b[n]; + for(int i=0;i<=k;i++){ + count[i] = 0; + } + for(int j=0;j=0;j--){ + count[(a[j]/pos)%10]--; + b[count[(a[j]/pos)%10]] = a[j]; + + } + for(int i=0;i0;pos *= 10){ + countSort(a,n,pos); + } + +} + + +void printArray(int arr[],int n){ + printf("\nPrinting the Array: \n"); + for(int i=0;i",arr[i]); + } +} + +int main(){ + int arr[] = {432,8,530,90,88,23,11,45,677,199}; + int n = sizeof(arr)/sizeof(arr[0]); + printArray(arr,n); + radixSort(arr,n); + printArray(arr,n); + + + + return 0; +}