Bonjour,
Mon programme ne trie pas (par insertion). Voilà mon code :
output de mon programe:
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 int i; int temp=0; for(i=0;i<nb;i++) { System.out.print("Entrez les éléments:"+(i+1)+" = "); tab[i]=sc.nextInt(); int posmaxi=i; for(int j=i+1;j<nb;j++) { if(tab[j]<tab[posmaxi]) { posmaxi=j; } temp=tab[posmaxi]; tab[posmaxi]=tab[i]; tab[i]=temp; } } System.out.println(tab[i]); } }
Entrez taille de tableau soit <10 :4
Entrez les éléments:1 = 5
Entrez les éléments:2 = 2
Entrez les éléments:3 = 3
Entrez les éléments:4 = 7
0
Partager