Commit | Line | Data |
---|---|---|
98c13508 JB |
1 | #include <stdio.h> |
2 | ||
8bfd43bc | 3 | void permuter(int T[], int i1, int i2) { |
98c13508 JB |
4 | int tmp = T[i1]; |
5 | T[i1] = T[i2]; | |
6 | T[i2] = tmp; | |
7 | } | |
8 | ||
9 | int i_min(int T[], int n, int d) { | |
10 | int min = d; | |
11 | for (int i = d+1; i < n; i++) { | |
12 | if (T[i] < T[min]) { | |
13 | min = i; | |
14 | } | |
15 | } | |
16 | return min; | |
17 | } | |
18 | ||
19 | void SelecEch(int T[], int n) { | |
20 | int imin, d = 0; | |
21 | while (d < n-1) { | |
22 | imin = i_min(T, n, d); | |
6eb44436 | 23 | permuter(T, d, imin); |
98c13508 JB |
24 | d++; |
25 | } | |
26 | } | |
27 | ||
28 | void AfficheTab(int T[], int n) { | |
29 | for (int i = 0; i < n; i++) { | |
8bfd43bc | 30 | printf("T[%d]=%d\n", i, T[i]); |
98c13508 JB |
31 | } |
32 | } | |
33 | ||
34 | int main() { | |
35 | int T[6] = {2, 5, 3, 1, 4, 6}; | |
36 | ||
37 | AfficheTab(T, 6); | |
38 | ||
39 | SelecEch(T, 6); | |
40 | ||
41 | AfficheTab(T, 6); | |
42 | ||
43 | return 0; | |
44 | } |