{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Sorting & Searching code

# Length aj firstifirst ifirst

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: { int iFirst = 0; // Next element to consider in the first array int iSecond = 0; // Next element to consider in the second array int j = 0; // Next open position in a while (iFirst < first.length && iSecond < second.length) { if (first[iFirst] < second[iSecond]) { a[j] = first[iFirst]; iFirst++; } else { a[j] = second[iSecond]; iSecond++; } j++; } (4) Quick Sort (5) Linear search (sequential search) while (iFirst < first.length) { a[j] = first[iFirst]; iFirst++; j++; } while (iSecond < second.length) { a[j] = second[iSecond]; iSecond++; j++; } } } public void sort(int from, int to) { if (from >= to) return; int p = partition(from, to); sort(from, p); sort(p + 1, to); } private int partition(int from, int to) { int pivot = a[from]; int i = from - 1; int j = to +...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online