Supose you have a group of N numbers and would like to determine the kth largest.
One way to solve this problem would to read N numbers into an array, sort them in
decreasing order by some simple algorithm such as bubblesort, and then return the
element in position.
Here is what the problem is asking for
Write a program to solve this problem. Let k = N/2. Draw a table showing the running time of your program for various values of N.
Can some one get me started on the code for this problem or explain it better to me.
Input file: 300 5000 300000 200000 30 45 70 500000 3000
Code:#include< iostream > #include< fstream > const int MAXVALUES = 9; using namespace std; int main() { //Declare the streams and the input and output files ifstream inFile; ofstream outFile; inFile.open("A:/input1.txt"); outFile.open("A:/output1.txt"); int i = 0; int j = 0; int temp = 0; int sortValue[MAXVALUES]; for(i=0; i<MAXVALUES; i++) { inFile>> sortValue[i]; } inFile.close(); for(i=0;i<MAXVALUES-1;++i) { for(j=0;j<MAXVALUES-1;j++) { if(sortValue[j+1] > sortValue[j]) { temp = sortValue[j]; sortValue[j] = sortValue[j+1]; sortValue[j+1] = temp; } } } for(i=0;i<MAXVALUES;i++) outFile<< "Array[" << i << "] : " << sortValue[i] << endl; return 0; }