trie de bulles
void bubbleSort() {
//Big O is n2
nElems = list.length;
int out, inside;
int swaps = 0, comp = 0;
for (out = nElems - 1; out >= 1; out--) {
for (inside = 0; inside < out; inside++) {
comp++;
if (list[inside] > list[inside + 1]) {
//Swap
int temp = list[inside];
list[inside] = list[inside + 1];
list[inside + 1] = temp;
swaps++;
}
}
}
print('number of swaps is $swaps and compressions is $comp ');
}
Old-fashioned Okapi