Java: BubbleSort algorithm

Java

Video is ready, Click Here to View ×


Animated demo tutorial on BubbleSort sorting algorithm, with example implementation code in Java, and performance analysis. Get the code from my github site here:
www.github.com/joeyajames/Java

20 thoughts on “Java: BubbleSort algorithm

  1. **************Buble Sort Code ***********

    public static int[] bubleSort(int [] numArray) {
    int temp = 0;
    for(int i=0;i<numArray.length -1;i++) {
    for(int j=0;j<numArray.length-1-i;j++) {
    if(numArray[j] > numArray[j+1]) {
    /*if number on the left greater that to it's immediate right, just Swap */
    temp = numArray[j];
    numArray[j] =numArray[j+1];
    numArray[j+1] = temp;
    }
    }
    }
    return numArray;
    }

  2. hello man
    this is my code i wrote by myself could check it
    i run it in my netbeans and it have not any error but the program not work
    …………………………………………………………………………………………………………………..
    package bbsort;
    import java.util.Scanner;
    public class BbSort {

    public static void main(String[] args) {
    Scanner SC = new Scanner(System.in);
    System.out.println("enter size of array");
    int number=SC.nextInt();

    int array[]=new int[number];

    System.out.println("the size of array is "+" "+number);
    System.out.println("enetr elemets");
    for(int i=0; i<array.length;i++){
    array[i]=SC.nextInt();}

    System.out.println("elemets before sorting ");
    for(int show=0; show<array.length; show++){
    System.out.print(array[show]+" "); }

    for(int a=0; a<array.length; a++){
    for(int b=0; b<array.length;b++){
    if(array[b]>array[b+1]){
    int swap=array[b];
    array[b]=array[b+1];
    array[b+1]=swap;
    }}}

    for(int print=0; print<array.length; print++){
    System.out.println(array[print]);}} }

Leave a Reply

Your email address will not be published. Required fields are marked *