Watch the sorts看排序如何进行

Twelve sorts from sorting/ rearrange the same numbers, replayed one step at a time. Every bar that moves is a write the real code made.

sorting/ 里的十二种排序处理同一组数,一步一步回放。柱子的每一次变化,都是真实代码做的一次写入。

How it works原理

Each sort is the same function that the tests check, imported from sorting/. Before you press Play, the page runs it once on a Proxy of the numbers, which records every read, write and comparison without changing what the sort does, and then replays that record. Racing two sorts gives both the same number of steps per second, so the one that needs fewer operations finishes first.

每种排序都是测试检查过的同一个函数,从 sorting/ 引入。你按下播放之前,页面先在这组数的 Proxy 上把它运行一遍:Proxy 记下每一次读、写和比较,但不改变排序的行为;播放就是回放这份记录。两种排序比赛时,每秒走同样多的步数,所以需要操作更少的那个先完成。

The copying merge sort and the copying quick sort are not here: they build new arrays instead of rearranging the one they are given, so there are no writes to replay. The visualizer README explains the rest.

复制式归并排序和复制式快速排序不在这里:它们创建新的数组,而不是重排传入的那个,所以没有写操作可以回放。其余细节见可视化的 README。