This question already has an answer here:

I try to make an animation of sorting like this but something goes wrong.

list = RandomInteger[100, 20]
step = 1;
Animate[BarChart[Sort[list, (step++ < limit && #1 < #2) &]], {limit,
1, 100}, AnimationRunning -> False]

marked as duplicate by MarcoB, m_goldberg, J. M. will be back soon Mar 27 at 23:01

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ Output all steps of Sort is perhaps the closest to your question, in that it implements the visualization as an animated bar chart. Also relevant: How can I collect data for visualization of quick sort?. $\endgroup$ – MarcoB Mar 27 at 21:38
  • 1
    $\begingroup$ I disagree about this being marked a duplicate. None of the linked answers actually show how to visualise the sorting algorithm employed by Sort. The linked answers all implement their own sorting algorithms, which is not what is being asked here. $\endgroup$ – Sjoerd Smit Mar 28 at 9:26

You were almost there:

list = RandomInteger[100, 10];
 Block[{step = 1},
  BarChart[Sort[list, (step++ >= limit || OrderedQ[{#1, #2}]) &]]
 {limit, 1, 100, 1},
 AnimationRunning -> False

enter image description here

Very nice idea, I must say. I don't know if I would've come up with that on my own.


Not the answer you're looking for? Browse other questions tagged or ask your own question.