void divide(int a[], int n, int begin, int end, int k) { if (begin > end) { return; } int pivot = a[end]; int p = begin; int q = begin-1; while (p < end) { if (a[p] > pivot) { q++; swap(a[p], a[q]); } p++; } swap(a[q+1], a[end]); int result = q+1; if (result == k-1) { return; } else if (result > k-1) { divide(a, n, begin, result-1, k); } else { divide(a, n, result+1, end, k-(result+1)); } } int fun(int a[], int n) { divide(a, n, 0, n-1, 2); if (a[0] < a[1]) { return a[0]; } return a[1]; }