-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstat.js
More file actions
107 lines (88 loc) · 2.43 KB
/
stat.js
File metadata and controls
107 lines (88 loc) · 2.43 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
function triBulle(L) {
var compteurEchange = 0;
var compteurCompa = 0;
for (let i = 0; i < L.length - 1; i++) {
for (let j = 0; j < L.length - 1; j++) {
compteurCompa++
if (L[j + 1] < L[j]) {
var tempo = L[j];
L[j] = L[j + 1];
L[j + 1] = tempo;
compteurEchange = compteurEchange + 3
}
}
}
return compteurCompa + compteurEchange;
}
function triBulleOpti(list) {
var compteurEchange = 0;
var compteurCompa = 0;
for (let i = 0; i < list.length - 1; i++) {
tableauTrie = true;
for (let j = 0; j < list.length - 1; j++) {
compteurCompa++
if (list[j + 1] < list[j]) {
var tempo = list[j];
list[j] = list[j + 1];
list[j + 1] = tempo;
compteurEchange = compteurEchange + 3
tableauTrie = false;
}
}
if (tableauTrie) {
break;
}
}
return compteurCompa + compteurEchange;
}
function insertion(list) {
var compteurEchange = 0;
var compteurCompa = 0;
var test, i, j;
for (i = 1; i < list.length; i++) {
test = list[i]
j = i - 1
while (j >= 0 && list[j] > test) {
compteurCompa++
list[j + 1] = list[j]
j--
}
list[j + 1] = test
compteurEchange = compteurEchange + 3
}
return compteurCompa + compteurEchange;
}
function selection(list) {
var compteurEchange = 0;
var compteurCompa = 0;
for (var i = 0; i < tab.length; i++) {
for (var j = i + 1; j < tab.length; j++) {
compteurCompa++
if (tab[j] < tab[i]) {
var tmp = tab[i];
tab[i] = tab[j];
tab[j] = tmp;
compteurEchange = compteurEchange + 3
}
}
}
return compteurCompa + compteurEchange;
};
function stat(min, max, step, nbr) {
for (let i = min; i <= max; i = i + step) {
var tempStat = 0;
for (let j = 0; j < nbr; j++) {
var tbl = [];
for (let k = 0; k < i; k++) {
tbl.push(Math.floor(Math.random() * 100))
}
tempStat += triBulleOpti(tbl)
}
console.log(`${i} : ${tempStat / i}`);
}
}
var min = 10;
var max = 20;
var step = 5;
var nbr = 10;
stat(min, max, step, nbr)