Say that the different values in an unsorted array are only
Say that the different values in an unsorted array are only 10 values (each repeating many times). Give an algorithm to sort the array. Example: in there are many numbers but only 3 different values.
Solution
void selection_sort(int arr[],int n)
{
int i=0;
int j=0;
for(i=0;i<n-1;i++)
{
int minindex =i;
for(j=i+1;j<n;j++)
{
if(arr[j]<arr[minindex])
minindex =j;
}
swap(arr[minindex],arr[i]);
}
}
