Bonjour, ce programme indique l'erreur suivante: "Check class headers... parsing individual files failed!"
Pour les curieux ce programme est censé renvoyer le temps de calcul d'une dichotomie. En d'autres termes, combien de temps prend un programme en log2(n).
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 // one class needs to have a main() method public class HelloWorld { // arguments are passed using the text field below this editor public static void main(String[] args) { long debut = System.currentTimeMillis(); int min=0; int max=1000000; int x= 548425; int milieu; int t[]={1,2,3,4,5,6,7,8,9,10}; int i; int j; int k; int dichotomie( int min, int max, int x, int t[]){ if(min>max){return -1;} else{ milieu=(min+max)/2; if(milieu=x){return milieu;} else if(x<milieu){ max=milieu; return dichotomie(min, max,x); } else{min=milieu; return dichotomie(min,max,x); } } } dichotomie(min, max, x, t); System.out.println(System.currentTimeMillis()-debut); } }
J'ai essayé d'aller prendre un code sur internet mais l'erreur "illegal start of expression public int binarySearch(int key)" en plus de 2 points virgules qui manqueraient.
Merci, pour votre futur aide.
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 // one class needs to have a main() method import java.util.Arrays; public class HelloWorld { // arguments are passed using the text field below this editor public static void main(String[] args) { int min=0; int max=10; int x= 458645; int milieu; int t[]=new int[1000000]; int i; int j; int k; for (i=0; i<1000000; i++){t[i]=i;} long debut = System.currentTimeMillis(); int[] data; int size; public int binarySearch(int key) { int low = 0; int high = size - 1; while(high >= low) { int middle = (low + high) / 2; if(data[middle] == key) { return 1; } if(data[middle] < key) { low = middle + 1; } if(data[middle] > key) { high = middle - 1; } } return 0; }; System.out.println(System.currentTimeMillis()-debut); } }
Partager