Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

Bubble Sort Java

public void bubbleSort(java.util.ArrayList aList) {
        int n = aList.size();
        int temp = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 1; j < (n - i); j++) {
                if (aList.get(j - 1) > aList.get(j)) {
                    //swap elements  
                    temp = aList.get(j - 1);
                    aList.set(j-1, aList.get(j));
                    aList.set(j, temp);
                }
Source by favtutor.com #
 
PREVIOUS NEXT
Tagged: #Bubble #Sort #Java
ADD COMMENT
Topic
Name
3+2 =