0
I need to make a vector ordering code using recursion. I looked into the sorting methods and found two that would be interesting: Lection Sort and Quicksort. However, I tried to use Selection Sort and I was not successful. Follow my code:
#include <stdio.h>
#include <stdlib.h>
int numeros[5];
int i;
void Ordenar(int numeros[], int i, int j){
int aux;
int menor;
if(i==3){
for(i=0; i<5; i++){
printf("%d", numeros[i]);
}
return 0;
}
if(j==4){
return Ordenar(numeros, i+1, i+2);
}
if(numeros[i]>numeros[j]){
menor = j;
aux = numeros[j];
numeros[menor] = numeros[i];
numeros[i] = aux;
}
else{
return Ordenar(numeros, i, j+1);
}
}
int main(){
for(i=0; i<5; i++){
scanf("%d", &numeros[i]);
}
Ordenar(numeros, 0, 1);
return 0;
}
The idea was to leave the first number still and compare them with all the others, until finding the smallest. Then, do the same with the second, third etc.
Another question: what is best used to sort an array with recursion: Selection Sort or quicksort?