/* Sortiranje niza celih brojeva - Selection sort algoritam */ #include /* Funkcija sortira dati niz brojeva koji ima n elemenata */ void selection_sort_int(int a[], int n) { int i, j; /* Na svaku poziciju od 0 do pretposlednje */ for (i = 0; i < n-1; i++) /* Dovodimo minimalni element ostatka niza */ for(j = i+1; j < n; j++) if (a[i] > a[j]) { int tmp = a[i]; a[i] = a[j]; a[j] = tmp; } } void selection_sort_float(float a[], int n) { int i, j; for(i=0; i a[j]) { float pom=a[i]; a[i]=a[j]; a[j]=pom; } } int main() { int a[] = {5, 8, 2, 4, 1, 9, 3, 7, 6}; int n = sizeof(a)/sizeof(int); int i; float b[] = {5.0, 8,2, 2.9, 4.4, 1.1, 9.8, 3.1, 7.3, 6.6}; int m = sizeof(b)/sizeof(float); selection_sort_int(a, n); for (i = 0; i < n; i++) printf("%d ", a[i]); printf("\n"); selection_sort_float(b, m); for (i = 0; i < m; i++) printf("%.2f ", b[i]); printf("\n"); return 0; }