i am doing a project to help visualize sorting algorithms and I'm facing a problem.
To help visualize the sorting process of an algorithm, I must show every changings in the array during that said process.
The problem is that my array is updating in my view only once the sort is done and not during the process.
There are only integers in my arrays.
Here is my code to display the array :
<span *ngFor="let v of tab">
{{v}}
</span
And here is my controller : (the timeout is used to slow down the process)
public sort(tab) {
let start = performance.now();
console.log(start);
let smallest;
for (let i = 0; i < tab.length; i++) {
smallest = tab[i];
for (let j = i + 1; j < tab.length; j++) {
setTimeout(() => { }, 100000);
if (tab[j] < smallest) {
let tmp = tab[j];
tab[j] = smallest;
tab[i] = tmp;
smallest = tmp;
//This doesn't update the view
this.tab = tab;
}
}
}
//This does
this.tab = tab;
let end = performance.now();
console.log(end);
this.time = end - start;
The algo is probably not the most efficient but that's not the case ^^.