5

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]
Sjoerd Smit
  • 23,370
  • 46
  • 75
vederko-p
  • 53
  • 3

1 Answers1

7

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
]

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.

Sjoerd Smit
  • 23,370
  • 46
  • 75