1. Example for Bubble sort is given below
2. Bubble sort (ascending order):
Consider the first 2 elements of the numbers and compare it. 32 is greater than 21 then interchange both of them. Then the numbers are
21, 32, 9, 17, 5
Next compare 32 and 9. Here 32 is greater so interchange both of them. Then the numbers are
21, 9, 32, 17, 5
Next compare 32 and 7. Then interchange and the numbers are
21, 9, 17, 32, 5
Next compare 32 and 5. Then interchange and the numbers are
21, 9, 17, 5, 32.
After the first phase the largest number is on the right side. Similarly do the remaining. At last we will get the result as follows.
5, 9, 17, 21, 32