Learn Sort Linked List of 0s 1s and 2s with a step-by-step Linked Lists visualizer, JavaScript source code and a worked example. Practice rewiring and advanced.
INTERACTIVE EXECUTION STUDIO
LEARN BY DOING
Predict. Execute. Understand.
Follow the source code, inspect live state changes, and predict the next operation before revealing it.
Follow the computed execution on the reference input. Advance one step at a time, inspect the changing values and compare your prediction with the final output.
Example input
[
2,
1,
0,
2,
1
]
Execution steps
Append to matching chain
Computed output
[
0,
1,
1,
2,
2
]
JavaScript reference implementation
const solve = (a,s)=>{
let b=[[],[],[]];
a.forEach(x=>{
b[x].push(x);
s("Append to matching chain",{
Zero:b[0],One:b[1],Two:b[2]
})
});
return b.flat()
};