I have 4 sorting algorithms which I want to visualize. I want to make them run at the same time. Should I write functions like bubbleSortStep
instead of just bubbleSort
to call it every second for example and execute one step. For example like this:
setInterval(() => {
bubbleSortStep()
insertionSortStep()
quicksortStep()
}, 1000)
Or is it going to work fine if I create the sorting functions the normal way and add an interval to each of them like:
bubbleSort() {
setInterval(() => {
// sorting...
}, 1000)
}
...same for other three, and call them afterwards.
bubblesort()
insertionSort()
quicksort()
The idea is coming from YouTube videos like this where the colors change all at once.