Use the bubble sort to sort 3 1 5 7 4 showing the lists obta
Use the bubble sort to sort 3; 1; 5; 7; 4; showing the lists obtained at each step.
Solution
in bubble sort the maximum goes to the last in every step and then comparison is done for the remaining and then again the largest moves to the end and the process continues, as shown
step 1 ) 3; 1; 5; 7; 4;
as 3 > 1 swap 1; 3; 5; 7; 4;
as 3<5 .....no change 1; 3; 5; 7; 4;
5<7 ------no change 1; 3; 5; 7; 4;
7>4 ------swap 1; 3; 5; 4; 7;
step 2 ) 1; 3; 5; 4; 7;
1<3 ----no change 1; 3; 5; 4; 7;
3<5-----no change 1; 3; 5; 4; 7;
5>4 -----swap 1; 3; 4; 5; 7;
5<7 -----no change 1; 3; 5; 4; 7;
so the sorted array is 1; 3; 5; 4; 7;
