Question: C++ I have this code it takes 5 txt files source1.txt-source5.txt they are [10000][1] files the files have an integer 1-10000 randomly scattered and each

C++

I have this code

it takes 5 txt files source1.txt-source5.txt they are [10000][1] files

the files have an integer 1-10000 randomly scattered and each column number is a page

then it creates a combRank array that is [10000][1] as well

The combRank array is the sum of each column between the 5 sources

so...source1 col 1 + source2 col 1 + source3 col 1 + source4 col 1 + source5 col 1 for each column

Then we create the combRank into a [10000][2] array that associates a page number with that column

then I created a quickSort algorithm to sort the combRank array that is now a [10000][2] array by ascending order

*********************

I need help to sort the sources how the quicksorted combRank array is sorted

then I need help creating an inversion counter of the newly sorted source and its old source

*********************

#include #include #include using namespace std;

void swap(int* a, int* b) { int x = *a; *a = *b; *b = x; }

int partition(int array[][2], int low, int high) { int pivot = array[high][0]; int i = (low - 1); for (int j = low; j <= high - 1; j++) { if (array[j][0] < pivot) { i++; swap(&array[i][0], &array[j][0]); swap(&array[i][1], &array[j][1]); } } swap(&array[i + 1][0], &array[high][0]); swap(&array[i + 1][1], &array[high][1]); return (i + 1); }

void quickSort(int array[][2], int low, int high) { if (low < high) { int pi = partition(array, low, high); quickSort(array, low, pi - 1); quickSort(array, pi + 1, high); } }

int main() { cout << "Hello World! "; int x;

int source1[10000][2]; //each source array holds 10000 ranks and 10000 page numbers int source2[10000][2]; int source3[10000][2]; int source4[10000][2]; int source5[10000][2]; int combRank[10000][2]; //Combined rank array ifstream file1("source1.txt"); int cnt= 0; //counts how many times through while loop while (file1 >> x) //Series of while loops that load a seperate array for each source file with data { source1[cnt][0] = x; source1[cnt][1] = cnt+1; cnt++; } file1.close();

ifstream file2("source2.txt"); cnt= 0; while (file2 >> x) { source2[cnt][0] = x; source2[cnt][1] = cnt+1; cnt++; } file2.close();

ifstream file3("source3.txt"); cnt= 0; while (file3 >> x) { source3[cnt][0] = x; source3[cnt][1] = cnt+1; cnt++; } file3.close();

ifstream file4("source4.txt"); cnt= 0; while (file4 >> x) { source4[cnt][0] = x; source4[cnt][1] = cnt+1; cnt++; } file4.close();

ifstream file5("source5.txt"); cnt= 0; while (file5 >> x) { source5[cnt][0] = x; source5[cnt][1] = cnt+1; cnt++; } file5.close();

//couts to test make sure arrays work correctly cout << " source array test "; cout << source1[9999][0] << " : " << source1[9999][1] <<" "; cout << source2[2][0] << " : " << source2[2][1] <<" "; cout << source3[0][0] << " : " << source3[0][1] <<" "; cout << source4[0][0] << " : " << source4[0][1] <<" "; cout << source5[0][0] << " : " << source5[0][1] <<" ";

for (int i = 0; i < 10000; i++) //for loop that sums each rank from source arrays and stores them into the combined rank array { int rankSum = source1[i][0] + source2[i][0] + source3[i][0] + source4[i][0] + source5[i][0]; combRank[i][0] = rankSum; combRank[i][1] = i + 1; } cout << " Comb Rank array test "; cout << combRank[0][0] << " : " << combRank[0][1] <<" "; cout << combRank[1][0] << " : " << combRank[1][1] <<" "; cout << combRank[2][0] << " : " << combRank[2][1] <<" "; cout << combRank[3][0] << " : " << combRank[3][1] <<" "; cout << combRank[4][0] << " : " << combRank[4][1] <<" ";

quickSort(combRank, 0, 10000);

for (int i = 0; i < 10000; i++) //prints entire combrank array for testing { cout << combRank[i][0] << "\t\t:" << combRank[i][1] << " "; } cout << " "; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!