Insertion Sort Visualizer
Current line
Previous line
for (int j = 1; j < n; j++) {
int temp = elements[j];
int p = j;
while (p > 0 && temp < elements[p-1]) {
elements[p] = elements[p-1];
p--;
}
elements[p] = temp;
}
// done ✅
Press Step or Play to begin.
while (p > 0 && temp < elements[p-1]) { ... }
j: -
p: -
temp: -
Comparisons: 0
Shifts: 0
Insertions: 0
Passes: 0