← DSA I Interactive execution lab

Sorting Arena

Run the same values through three classic algorithms and inspect every operation.

Choose an algorithm

Try negatives and duplicate values too.

1void bubbleSort(std::vector<int>& a) {
2 for (size_t i = 0; i + 1 < a.size(); i++) {
3 bool swapped = false;
4 for (size_t j = 0; j + 1 < a.size() - i; j++) {
5 if (a[j] > a[j + 1]) {
6 std::swap(a[j], a[j + 1]);
7 swapped = true;
8 }
9 }
10 // largest remaining value settled on the right
11 if (!swapped) break;
12 }
13}
start

Ready to bubble

Step 1 of 37
7 [0]
3 [1]
5 [2]
2 [3]
9 [4]
1 [5]
Active indices Sorted region
Pass0
Comparisons0
Writes0
Swaps0
1 / 37