I have an assignment to modify the selection sort to sort all of the values on the odd positions of an array in ascending order and to sort all of the values on the even positions in descending order. I am currently working on the oddSort function
void oddSort(int arrSize, int arr[]){
int i;
int lastOdd;
int currentMin;
lastOdd = findLastOdd(arrSize);
for(i=0; i<lastOdd; i+=2){
if(i=0){
currentMin = arr[i];
}
else if (arr[i] < currentMin){
swap(&arr[i], ¤tMin);
}
}
}
but, when I try to apply this function to an array and print the output for it the compiler returns nothing.
int main(){
int arrayOne[10] = {246, 101, 223, 228, 1, 249, 99, 111, 191, 126};
int i;
oddSort(10, arrayOne);
for(i=0; i<10; i++){
printf("%d ", arrayOne[i]);
}
return 0;
}
My pseudocode for the evenSort function is similar to the oddSort function so I will assume that that won't work either. I checked the swap and findLastOdd functions independently and they work, so I am sure that there is something wrong with the oddSort function itself. Any ideas as to what? edit: here are the rest of the user defined functions in my code
int findLastOdd(int someNumber){//to give the oddSort function a stopping point
if(someNumber % 2 == 0){
return someNumber - 1;
}
else{
return someNumber;
}
}
int findLastEven(int someNumber){//to give the evenSort function a starting point
if(someNumber % 2 == 0){
return someNumber;
}
else{
return someNumber - 1;
}
}
void swap (int* a, int* b){// swaps two array elements using pointers
int temp;
temp = *a;
*b = *a;
*b = temp;
}