-
Notifications
You must be signed in to change notification settings - Fork 0
/
TriPairImpairL.java
45 lines (31 loc) · 1.25 KB
/
TriPairImpairL.java
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
35
36
37
38
39
40
41
package Etape3V0.PairImpairLexico;
import Tris.PairImpair.Buffer;
import Tris.PairImpair.ComparateurPI;
import trisEtTest.CoupleResult;
public class TriPairImpairL {
public static CoupleResult[] tri (CoupleResult[] tab) {
int nMax=tab.length;
CoupleResult[] tabTrie = new CoupleResult[nMax];
ComparateurPIL[] cmp = new ComparateurPIL[nMax];
BufferL lg,eg,ld,ed;
lg = null; eg = null;
for (int i=0;i<nMax-1;i++) { // creation des threads
ld = new BufferL();
ed = new BufferL();
cmp[i]= new ComparateurPIL(i,tab[i],nMax,tabTrie,lg,eg,ld,ed);
lg = ed; eg = ld;
};
ld = null; ed = null; // creation du dernier thread
cmp[nMax-1] = new ComparateurPIL(nMax-1,tab[nMax-1],nMax,tabTrie,lg,eg,ld,ed);
for (int i=0;i<nMax;i++) { // execution des threads
cmp[i].start();
};
for (int i=0;i<nMax;i++) { // attente des resultats
try { cmp[i].join(); } catch (InterruptedException e) {} ;
};
/*for (int i=0;i<nMax;i++) { // affichage resultats
System.out.println(tabTrie[i].s +"de generation"+tabTrie[i].i);
};*/
return tabTrie;
}
}