I try to make an animation of the sorting steps taken by Sort 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]
I try to make an animation of the sorting steps taken by Sort 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]
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.
Sort. The linked answers all implement their own sorting algorithms, which is not what is being asked here. – Sjoerd Smit Mar 28 '19 at 09:26Animate[BarChart[ Block[{step = 1}, Sort[list, (#1 < #2 \[Implies] step++ > limit) &]]], {limit, 1, 100}, AnimationRunning -> False]– Michael E2 Jul 21 '20 at 17:50