![bubble sort bubble sort](https://3.bp.blogspot.com/-rzUTGx1fUfY/U-zCFncNoRI/AAAAAAAABx4/YBwz3fXou9A/s1600/Java%2BBubble%2BSort%2BExample.png)
Now it continues to make another sweep again from the left.
#BUBBLE SORT FULL#
Note that after one full sweep bubble sort has made the largest element to be the final element in the array. So after one full sweep of the array (the position before the green line above), bubble sort has arrived at. Finally, 95 and 21 are compared and found to be in an incorrect order, so they are swapped. 67 and 95 are already in order so no swapping needs to be done. So bubble sort swaps them so that the array becomes, as shown above in the second step. They are already in order, so nothing needs to be done. To begin with, bubble sort compares every adjacent pair of elements beginning from the left. We will show how bubble sort works by showing the first few steps. We are given the array and desire to sort it in increasing order, so that 12 becomes the first element and 95 becomes the last element. Below is a simple illustration of how bubble sort works. It is called bubble sort because the largest element “bubbles” to its correct, intended, location, followed by the bubbling of the second largest element to its location and so on. This process is continued over and over again till the full array is sorted. The way bubble sort works is to compare every successive pair of elements in an array and swapping them if they are not in the right order. It is often the first sorting algorithm taught in an algorithms course. How does bubble sort work? Bubble sort is one of the simplest sorting algorithms to understand and implement.
![bubble sort bubble sort](https://image.slidesharecdn.com/unit6jwfiles-130410134758-phpapp02/95/unit6-jwfiles-4-638.jpg)
As a second example, Google Maps sorts routes to your destination by distance and presenting them in order of shortest-to-longest or fastest-to-slowest. For instance, Google is ranking webpages according to their suitability for your query and then sorting them so that the webpage with the highest relevance is presented first. What is the sorting problem? We are given an array of elements, e.g., numbers, and we desire to put them in order, either increasing or decreasing order.