#include #include #include /* * Chooses a random pivot in A[p...r] and partitions the array such that * all elements smaller than the pivot lie on its left and all elements * larger than the pivot lie on its right. * Returns the position of the pivot in the partitioned array. */ int partition(int *A, int p, int r) { int i = p + rand() % (r - p + 1); // generate a random number in {p, ..., r} int temp = A[r]; A[r] = A[i]; A[i] = temp; // swap A[r] and A[i] int x = A[r]; i = p - 1; for(int j=p; j 0 && i <= N) { printf("'%d'th order statistic :\n", i); printf("\tRecursive selection : %d\n", recursiveSelect(arr, 0, N-1, i)); printf("\tIterative selection : %d\n", iterativeSelect(arr, N, i)); printf("Enter i (0 to exit): "); scanf("%d", &i); } return 0; }