int getMin(int numbers[], int size);
int main(){
int numbers[10] = {0, 2, 4, 6, 1, 3, 8, 7, 9, 5};
int res = getMin(numbers, 10);
printf("%d\n", res);
}
int getMin(int numbers[], int size){
int key;
int min = numbers[0];
for(int i = 0; i < size; i++){
if(min > numbers[i]){
min = numbers[i];
key = i;
}
}
return min;
}
#include <stdio.h>
int getMin(int numbers[], int size, int shift);
void swap(int numbers[], int key, int shifted);
int main(){
int numbers[10] = {0, 2, 4, 6, 1, 3, 8, 7, 9, 5};
int min = 0;
for(int i = 0; i < 10; i++){
min = getMin(numbers, 10, i);
swap(numbers, min, i);
printf("min: %d; i: %d\n", min, i);
}
printf("\n");
}
void swap(int numbers[], int key, int shifted){
int buffer = numbers[key];
numbers[key] = numbers[shifted];
numbers[shifted] = buffer;
}
int getMin(int numbers[], int size, int shift){
int key = 0;
int min = numbers[shift];
for(int i = shift; i < size; i++){
if(min > numbers[i]){
min = numbers[i];
key = i;
}
if(shift == (size - 1)){
key = shift;
}
}
return key;
}