Bonjour,
Je cherche à faire une tri à bulle. Voici mon programme:
Je cherche à le tester mais j'ai un problème de compilation au niveau de la ligne écrite en rouge:
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 import java.util.*; public class triabulle{ public static void sort(Comparable[]tab){ boolean b=false; while(b==false){ b=true; for(int i=0; i<tab.length-1; i++){ if(tab[i+1].compareTo(tab[i])<0){ Comparable aux=tab[i]; tab[i]=tab[i+1]; tab[i+1]=aux; b=false; } } } } public static void main (String[]args){ Double[]x={new Double(12.5), new Double(3.0), new Double(-2.1), new Double(4),new Double(0.25), new Double(10), new Double (5.2)}; sort(x); for(int i=0; i<x.length; i++){ System.out.println(x[i]+" "); } } }
sort(Comparable[]) in triabulle cannot be applied to (java.lang.Double[])
sort(x);
Mais je ne comprends pas pourquoi vu qu'un double est un comparable.
Merci d'avance
Partager