Bubble Sort cont.
Outer loop: Start with unordered data { 7, 3, 66, 3, -5, 22, -77, 2};
Inner loop: for j = n(8) - 1 down to 1 do if (a[j-1] > a[j]) swap([j-1],a[j])
First pass: { 7, 3, 66, 3, -5, 22, -77, 2}; i = 0; j = 7
Second pass: { 7, 3, 66, 3, -5, -77, 22, 2}; i = 0; j = 6
Third pass: { 7, 3, 66, 3, -77, -5, 22, 2}; i = 0; j = 5
Fourth pass: { 7, 3, 66, -77, 3, -5, 22, 2}; i = 0; j = 4
Fifth pass: { 7, 3, -77, 66, 3, -5, 22, 2}; i = 0; j = 3
Sixth pass: { 7, -77, 3, 66, 3, -5, 22, 2}; i = 0; j = 2
Seventh pass: { -77, 7, 3, 66, 3, -5, 22, 2}; i = 0; j = 1
Second pass: { -77, -5, 7, 3, 66, 3, 2, 22}; i = 1
Third pass: { -77, -5, 2, 7, 3, 66, 3, 22}; i = 2
Fourth pass: { -77, -5, 2, 3, 7, 3, 66, 22}; i = 3
Fifth pass: { -77, -5, 2, 3, 3, 7, 22, 66}; i = 4
Sixth pass: { -77, -5, 2, 3, 3, 7, 22, 66}; i = 5
Seventh pass: { -77, -5, 2, 3, 3, 7, 22, 66}; i = 6