Example of Bubble Sort
Step1:
Given, array: [ 8,7,5,2] , traverse from pos=1 till pos=4 and swap the number with the previous element if it is less than the previous element.
Step 2:
Repeat the previous Step for pos=1 to pos=3
Step 3:
Follow Step 1 for pos=1 to pos=2
Step 4:
As now pos=1 to pos=1 means the array is now fully sorted
Java Program for Bubble Sort
Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in the wrong order. Bubble Sort in Java is not the best method to sort an array but is one of the most basic implementations for one to learn. In this article, we will learn how to write a program for Bubble Sort in Java.
Contact Us