Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

bubble sort for java ArrayList

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);
                }
            }
        }
    }
 
PREVIOUS NEXT
Tagged: #bubble #sort #java #ArrayList
ADD COMMENT
Topic
Name
6+9 =