1. Be innovative and design a user-friendly application
Note: the programming should take the list to search or sort at the running time, not compile time. [You are submitting the java code and the computed running time/time complexity of the algorithms
Insertion sort:
public static void sort(String[] a) {
int n = a.length;
for (int i = 1; i < n; i++) {
for (int j = i; j > 0; j--) {
if (a[j-1].compareTo(a[j]) > 0)
exch(a, j, j-1);
else break;
}
}
}
running time:
time complexities: "O(n^2)" and "O(n)"
Comments
Leave a comment