Sort Target
Algorithm
Speed
Normal ~12s · 38 ms/step
std::stable_sort (LLVM)(1998)
▶ Try this Source
O(n log n) ✓ Stable ✗ In-place
🔧 How it works

A re-implementation of LLVM libc++'s std::stable_sort: allocates an O(n) auxiliary buffer upfront, then recursively sorts both halves via ping-pong merging, alternating which buffer is the source and which is the destination at each recursion level. Falls back to Insertion sort for small sub-arrays.

🎯 Key property

The ping-pong strategy eliminates the copy-back step of standard Merge sort, each recursion level writes directly from one buffer to the other, so the sorted result always surfaces in the original array with no extra pass. Stability is guaranteed because merges always prefer the left half on equal elements.

👁 Watch for
  • RangeCopy a single O(n) allocation happens before recursion begins; data then alternates between the main array and the auxiliary buffer as the recursion unwinds
  • Compare merge steps use ≤ (IsLessOrEqual) to take from the left half when elements are equal, preserving the original relative order
  • IndexWrite Insertion sort handles sub-arrays at or below the small-sort threshold, writing results directly into whichever buffer is the current destination at that recursion depth
Initial State
This is the array before sorting. Follow std::stable_sort (LLVM) step by step.
Main Array
1
0
6
1
25
2
17
3
3
4
29
5
10
6
27
7
31
8
15
9
4
10
8
11
5
12
21
13
11
14
22
15
7
16
2
17
12
18
32
19
18
20
28
21
19
22
24
23
13
24
30
25
9
26
20
27
26
28
14
29
23
30
16
31
0 / 320 ops ( 0.0%) 0.0%
Sorting is
a spectacle.
Algorithms at work, in a daily vertical feed. Watch, play, challenge — and go deeper when you're ready.
Loading 0%
An unhandled error has occurred. Reload 🗙