I am making Bubble sort visualization algorithm and wanted to show to the process of shorting using line graph.
I have tried to implement the computed property but the browser hangs.
<template>
<div class="hello">
<h1>Bubble Sort</h1>
<p>{{ bubbleSort()}}</p>
<line-chart :data="bubbleSort()"></line-chart>
</div>
</template>
<script>
export default {
name: "HelloWorld",
data() {
return {
a : [12, 0, 4, 546, 122, 84, 98, 64, 9, 1, 3223, 455, 23, 234, 213]
}
},
methods : {
bubbleSort: function () {
let swapped;
do {
swapped = false;
for(var i = 0; i < this.a.length; i++){
if(this.a[i] > this.a[i+1]){
let temp = this.a[i];
this.a[i] = this.a[i+1];
this.a[i+1] = temp;
swapped = true;
}
}
}while(swapped);
return Object.assign({},this.a);
}
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
</style>
I expect the chart to update while shorting is happening.