Bonjour,
cela fait 2h que je cherche à traduire en java cet algorithme sans succès :
Voici ce que j'ai fait (comme parametre j'ai passé au départ biDirectionSort(0,n-1) avec n nombre de chiffre dans mon tableau) :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 tri(deb,fin) { g=deb; d=fin; pivot=tab[deb]; iterer iterer sortir quand (tab[d]<=pivot) d=d-1; fin-iterer sortir quand (g=d) tab[g]=tab[d]; tab[d]=pivot; g=g+1; iterer sortir quand (tab[g]>=pivot) g=g+1; fin-iterer sortir quand (g=d) tab[d]=tab[g]; tab[g]=pivot; d=d-1; fin-iterer si (g-1>deb) alors tri(deb,g-1) finsi si (fin>g+1) alors tri(g+1,fin) finsi }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 public void biDirectionSort(int start, int end) { int g=start; int d=end; int pivot=tab[start]; while((g!=d)&&(tab[d]>pivot)) {d--;} if(g!=d) { tab[g]=tab[d]; tab[d]=pivot; g++; } while((g!=d)&&(tab[g]<pivot)) {g++;} if(g!=d) { tab[d]=tab[g]; tab[g]=pivot; d--; } //g=d à ce stade if((g-1)>start) { biDirectionSort(start,(g-1)); } if(end>(g+1)) { biDirectionSort((g+1),end); } }
Partager