Question
Selection Sort Array DXC Automata Fix Questions AMCAT
void selectionSortArray(int len,int *arr)
{
int x=0,y=0;
for(x=0;x<len;x++)
{
int index_of_min=x;
for(y=x;y<len;y++)
{
if(arr[index_of_min]>arr[x]){
index_of_min=y;
}
}
int temp=arr[x];
arr[x]=arr[index_of_min];
arr[index_of_min]=temp;
}
}
-------------------------------------------
solution:
void selectionSortArray(int len,int *arr)
{
int x=0,y=0;
for(x=0;x<len;x++)
{
int index_of_min=x;
for(y=x;y<len;y++)
{
if(arr[index_of_min]>arr[y]){
index_of_min=y;
}
}
int temp=arr[x];
arr[x]=arr[index_of_min];
arr[index_of_min]=temp;
}
for(x=0;x<len;x++)
{
printf("%d ",arr[x]);
}
}