maincpp Modified from Programming Problem 4 on Page 94 mplem
main.cpp
Modified from Programming Problem 4 on Page 94 mplement the algorithm ksmall discussed in Section 2.4.4, as a C++ function. Use the first value of the array as the pivot. Use the main file Ba that tests the class with data from a text file Ba. Your code should work for any given file that has integers enumerated in a file (one value per line). Deliverables: 1. Source code for your class 2. Updated main file 3. Test output of your code e., the kth smallest value with given data file C) 4. A log file of traces e. log.txt) showing pivot value and state of the array after the partitioning of each roundSolution
int kSmallFirst (int k, int anArray[], int first, int last) { int pivotIndex = 0; if (k < pivotIndex - first + 1) return kSmallFirst(k, anArray, first, pivotIndex - 1); else if (k == pivotIndex - first + 1) return pivotIndex; else return kSmallFirst(k - (pivotIndex - first + 1), anArray, pivotIndex + 1, last); } int main () { int i = 0; int arr[512]; fstream data; data.open(\"data.txt\"); while (!data.eof()) { data >> arr[i]; i++; } data.close(); cout << kSmallFirst(42, arr, 0, i-1); return 0; }