data structures: java: bubble sort, selection, insertion sort

data structures: java: bubble sort, selection, insertion sort

Please read the instructions!!

I have the three codes for the bubble, selection, and insertion. You don’t need to create your own. This is less work.

public static void bubbleSort(int[] a) {
int outer, inner;
for (outer = a.length – 1; outer > 0; outer–) { // counting down

for (inner = 0; inner < outer; inner++) { // bubbling up if (a[inner] > a[inner + 1]) { // if out of order…

int temp = a[inner]; a[inner] = a[inner + 1]; a[inner + 1] = temp;

} } } }

public static void selectionSort(int[] a) { int outer, inner, min;

for (outer = 0; outer < a.length – 1; outer++) { // outer counts down min = outer;
for (inner = outer + 1; inner < a.length; inner++) {

if (a[inner] < a[min]) { } min = inner;

} // Invariant: for all i, if outer <= i <= inner, then a[min] <= a[i]

// a[min] is least among a[outer]..a[a.length – 1]

int temp = a[outer];
a[outer] = a[min];
a[min] = temp;
// Invariant: for all i <= outer, if i < j then a[i] <= a[j]

} }

public static void insertionSort(int[] array) { int inner, outer;

for (outer = 1; outer < array.length; outer++) { int temp = array[outer];
inner = outer;
while (inner > 0 && array[inner – 1] >= temp) {

array[inner] = array[inner – 1]; } inner–;

array[inner] = temp;

// Invariant: For all i < outer, j < outer, if i < j then a[i] <= a[j] }

}

"You need a similar assignment done from scratch? Our qualified writers will help you with a guaranteed AI-free & plagiarism-free A+ quality paper, Confidentiality, Timely delivery & Livechat/phone Support.


Discount Code: CIPD30



Click ORDER NOW..

order custom paper