I am new to programming and currently I am trying to write an algorithm for Selection Sort in recursion. I tried to pass the array[10] into the selection sort function I define before the main function and the selection sort function calls another function. After compiling this, it doesnt sort the array for some reason..Instead it adds an integer into the beginning of the array .I cant figure out what is wrong...
void helper_func(int arr[],int x,int y)
{
int tmp=0;
if(y<= (sizeof(arr))/(sizeof(int)))
{
if(arr[x]>arr[y])
{
tmp=arr[x];
arr[x]=arr[y];
arr[y]=tmp;
}
y=y+1;
helper_func(arr,x,y);
}
}
void SelectionSort(int arr[], int len)
{
if (len>1)
{
int x=sizeof(arr)/sizeof(int)-len;
int y=x;
helper_func(arr,x,y);
len=len-1;
SelectionSort(arr,len);
}
}
int main()
{
int array_a[10]={10,9,8,7,6,5,4,3,2,1};
SelectionSort(array_a, 10);
int x=0;
for(x=0;x<=sizeof(array_a)/sizeof(int)-1;x++)//checking what is in the arry
{
printf("%d...",array_a[x]);
}
return 0;
}