In this recipe, we will learn how to arrange some integers in ascending order using the bubble sort technique. In this technique, the first element is compared with the second, the second is compared with the third, the third with the fourth, and so on.
Arranging numbers in ascending order using bubble sort
How to do it…
Consider an array, arr, of size len elements. We want to arrange elements of the arr array in ascending order. Here are the steps to do so:
- Initialize a variable, say i, to len -2.
- Follow and repeat steps 3 through 5 as long as i >=1.  The value of i will be decremented by 1 after every iteration, that is, i=len-2, len-3, len-4, ....1.
- Initialize another variable, j, to 0.
- Repeat step...