Bubble sort algorithm for an integer array:
input: A = array of integers N = number of elements in A arrayIsSorted = false; while ( ! arrayIsSorted ) { arrayIsSorted = true; for (i = 0; i < N-1; i++) { if ( A[i] & A[i+1] are out of place ) { swap A[i] & A[i+1] arrayIsSorted = false; } } } |
Bubble sort algorithm for a String array:
input: A = array of String N = number of elements in A arrayIsSorted = false; while ( ! arrayIsSorted ) { arrayIsSorted = true; for (i = 0; i < N-1; i++) { if ( A[i] & A[i+1] are out of place ) { swap A[i] & A[i+1] arrayIsSorted = false; } } } |