Bubble sort in java

2 posts / 0 new
Last post
Bubble sort in java

Write a program that does bubble sort on an array?

Additional Info

Bubble sort is a simple sort, but not much used as there are many better sorting algorithms.

Question: Try to find out a situation where Bubble sort is advantageous.

Was it useful?
Bubble Sort Program

package com.javajee.myBubbleSort;

public class BubbleSort {

    int[] arrayElements= {9,4,10,6,8};
    public static void main(String[] args) {

        BubbleSort BS= new BubbleSort();

    //method to sort elements
    public void arrangeElements(int[]array,int length){
        int i=0;
        int j=0;
        int temp=0;
        //printing sorted array
        for(int e:array){

In bubble sort, we start with comparing first two elements and elements are swapped if first element is larger than second element. This process continues till the end of the array so that the largest element becomes the last element. Again the process starts from the beginning till the second last element. Process continues untill all the elements are sorted

Was it useful?

Search the Web

Custom Search

Searches whole web. Use the search in the right sidebar to search only within javajee.com!!!