2 ms·
With so few elements, I think you can perform the in-place swap as one animation. Take the pivot out, put an arrow on the first and last elements in the list, t
by Asooka 10y ago
With so few elements, I think you can perform the in-place swap as one animation. Take the pivot out, put an arrow on the first and last elements in the list, then
- if the left arrow points to an element greater than the pivot, swap the elements under the arrows and move the right arrow one cell left
- else if the right arrow points to an element less than the pivot, swap the elements under the arrows and move the left arrow one cell right
- else if one of the arrows points at the pivot, move the other arrow towards it
until the two arrows point at the same cell, which now contains the pivot. You could show the full selection animation the first time and then just move all elements to their final places at once every subsequent time. I would also replace the random pivot selection with selecting the middle-valued element among the first, middle and last element of the array.