salut tout le monde,

J'ai essayé de trier un tableau par selection
J'ai utilisé la classe suivante:

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
public class Trie {
int[] tab=new int[]{2,3,1,0,7};
int z;
	public Trie(){
 
		trierTableau(tab);
		afficherTableau(tab);
	}
 
	void trierTableau(int[] tableau){
		for(int i=0;i<tableau.length-1;i++)for(int j=i+1;j<tableau.length;j++){
			if(tableau[i]>tableau[j]){
				            permutation(tableau[i],tableau[j]);
			                 }
	}
	}
	void afficherTableau(int[] tableau){
		for(int i=0;i<tableau.length;i++)System.out.println(tableau[i]);
	}
 
	void permutation(int x,int y){
		z=x;
		x=y;
		y=z;
	}
 
	public static void main(String[] args) {
		new Trie();
 
	}
 
}
et ça n'a pas marché

tandis que avec la deuxième méthode constitué du code suivant:

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
public class Trie {
.............
	public Trie(){
		............
	}
 
	void trierTableau(int[] tableau){
		for(int i=0;i<tableau.length-1;i++)for(int j=i+1;j<tableau.length;j++){
			if(tableau[i]>tableau[j]){
				            permutation(i,j);
			                 }
	}
	}
	.........
	void permutation(int x,int y){
		z=tab[x];
		tab[x]=tab[y];
		tab[y]=z;
	}
 
	........
}
Donc, quelle est la difference entre ces deux methodes

Merci d'avence