Program to sort the nos using radix sort using C++

// Program to sort the nos using radix sort//

#include"iostream.h"
#include"conio.h"
#include"math.h"
#define SIZE 10
#define DIGIT 3

int main()

{
int a[SIZE],n,i,j,p,temp;
clrscr();
cout<<"Enter the no. of terms:";
cin>>n;
cout<<"Enter the terms:\n";
for(i=0;icin>>a[i];
for(p=1;p<=DIGIT;p++)
for(i=0; i< n-1; i++)
for(j=0;jif((a[j] % (int) pow(10,p))>(a[j+1]%(int) pow(10,p)))
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
cout <<"The sorted array is\n";
for (i=0 ; i < n; i++)
cout << endl << a[i];
getch();
return(0);
}

Post a Comment

Previous Post Next Post