cannot fix the error in the below radix sort code

#include<iostream>
#include<conio.h>
using namespace std;
void radix_sort(int*,int);
int count(int*,int);
main()
{
int a[20],n;
cout<<"\nEnter the no of element in array:";
cin>>n;

cout<<"\nEnter the elements of array:";
for(int i=0;i<n;i++)
cin>>a[i];

cout<<"\nInitial array:\t";
for(int j=0;j<n;j++)
cout<<a[j]<<"\t";

radix_sort(a,n);

getch();

}

int count(int *arr,int num)
{
int large,c=0;
for(int i=0;i<num;i++)
{
if(arr[i]>arr[i+1])
{
large=arr[i];
}
}

for(int y=large;y>=0;y=y%10)
{
c++;

}
cout<<"Maximum no of digit in largest no. is:"<<c;
return c;
}

void radix_sort(int *arr,int num)
{
int y=10;
int temp,c;

c=count(&arr[0],num);

for(int i=0;i<num;i++)
{

for(int j=0;j<num;j++)
{
if((arr[i]%y)>(arr[i+1]%y))
{
temp=arr[i];
arr[i]=arr[i+1];
arr[i+1]=temp;
}


}

if(c>1)
{
y*=10;
c--;
for(int k=0;k<num;k++)
cout<<"\nPass:"<<arr[k]<<"\t";
}
for(int p=0;p<num;p++)
cout<<"\nSorted:"<<arr[p]<<"\t";
}
}
Topic archived. No new replies allowed.