# How can I animate the sorting by Sort, BarChart and Animate? [duplicate]

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. is away♦Mar 27 at 23:01

• 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?. – MarcoB Mar 27 at 21:38
• 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. – Sjoerd Smit Mar 28 at 9:26

You were almost there:

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


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