Bubble Sort in Java

Bubble Sort is the simplest algorithm for sorting elements. In the Bubble sort algorithm, the array is traversed by comparing the current element with the next element each time. If the current element is greater than the next element then the positions will be swapped in this way the array will be sorted. As the complexity of this algorithm is Ο(n2) where n is the number of elements. This algorithm can not be used for large datasets. In this article, you are going to learn the Bubble sort algorithm program in Java.

Program

Following is the program for performing Bubble sort in Java.

The output should be:

Bubble Sort Program:

Items Before Sorting Array:
22 -45 38 10 -1 73 90 0 -6 7

Array After Bubble Sort
-45 -6 -1 0 7 10 22 38 73 90

LEAVE A REPLY

Please enter your comment!
Please enter your name here