Input Specification
The first line will have the integer
The next line will have
Output Specification
Print the initial block sequence, then after each time bubble sort swaps two elements, print the current block sequence.
Sample Input 1
Copy
2
2 1
Sample Output 1
Copy
2 1
1 2
Sample Input 2
Copy
6
9 1 2 6 4 7
Sample Output 2
Copy
9 1 2 6 4 7
1 9 2 6 4 7
1 2 9 6 4 7
1 2 6 9 4 7
1 2 6 4 9 7
1 2 6 4 7 9
1 2 4 6 7 9
Comments
This comment is hidden due to too much negative feedback. Show it anyway.
Clearly these 99 users are all hackers then
This comment is hidden due to too much negative feedback. Show it anyway.
Yes, because your code is incorrect and invokes undefined behaviour due to out-of-bounds array indexing. That's why you're getting a different number of WAs each run, because your code's behaviour is undefined.
If I am not mistaken this is neither Bubble nor selection, but some sort of hybrid. I am probably wrong but can someone explain?
This comment is hidden due to too much negative feedback. Show it anyway.
The bubble sort algorithm scans that array many times, each time swapping any adjacent elements that are out of order back into order. Once it swaps, it keeps searching through the rest of the array instead of going back to the beginning. Thus, the problem statement has the correct output.