do_something(a[1..n]) if do_something(a[1]) is o.k. return do_something(a[2..n])
do_something(a[1..n]) do_something(a[2..n]) if do_something(a[1]) is o.k. return
int find(a[1..n], x) if a[1] == x return i if 1 == n return -1 return find(a[2..n], x)See the C++ implementation.
int star_string(a[1..n]) i = star_string(a[2..n]) if a[1..n] forms a new longer star string set i properly return iSee the C++ implementation.
do_something(a[1..n]) if something a[1], return do_something(a[2..n])
do_something(a[1..n]) do_something(a[2..n]) if something a[1], return
sort(a[1..n]) sort(a[2..n]) if something a[1], return
sort(a[1..n]) if (n > 1) sort(a[2..n]) if something a[1], return
sort(a[1..n]) if (n > 1) sort(a[2..n]) for (i = 2; (i <= n) && (a[i - 1] > a[i]; i++) swap a[i - 1], a[i]
static void insertion_sort(int a[], int n) { if (n < 2) return; for (int i = n - 2; i >= 0; i--) { int t = a[i]; int j; for (j = i + 1; (j < n) && (t > a[j]); j++) a[j - 1] = a[j]; a[j] = t; } }
sort(a[1..n]) if something a[1], return sort(a[2..n])
sort(a[1..n]) if (n > 1) smallest = 1 for (i = 2; i <= n; i++) if a[smallest] > a[i], smallest = i swap a[smallest], a[1] sort(a[2..n])
void selection_sort(int a[], int n) { if (n < 2) return; for (int i = 0; i < n - 1; i++) { int smallest = i; for (int j = smallest + 1; j < n; j++) if (a[smallest] > a[j]) smallest = j; int t = a[i]; a[i] = a[smallest]; a[smallest] = t; } }
This page last modified on 3 December 2003.