#include #include using namespace std; // taken from page 680, Dale book void sort(int a[], int start, int end) { int passCount; int searchIndex; int minIndex; int tmp; for(passCount = start; passCount < end; passCount ++) { minIndex = passCount; for(searchIndex=passCount+1; searchIndex <= end; searchIndex ++) { if (a[searchIndex] < a[minIndex]) { minIndex = searchIndex; } } tmp = a[minIndex]; a[minIndex] = a[passCount]; a[passCount] = tmp; } return; } bool doInput(int & n, int & k) { cout << "Enter the size of your array -> "; cin >> n; cout << endl; if (n <= 0) { cerr << "Error, n must be positive" << endl; return (false); } cout << "Enter the value of k -> " ; cin >> k; cout << endl; if (k <= 0) { cerr << "Error, k must be positive" << endl; return (false); } if (n < k ) { cerr << "Error, k ("<< k << ") must be smaller than n (" << n <<")" << endl; return (false); } return(true); } void printArray(int ary[], int n) { int i; for(i=0; i < n ; i ++) { cout << ary[i] << " "; } cout << endl; } int main () { int n,k,i; int itemk; int *ary; int *tmpary; tms start, end; srand(time(NULL)); if(!doInput(n,k)) { cout << "Exiting " << endl; return -1; } ary = new int[n]; for(i=0;i