Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello C++ I have this code that takes 5 files, source1.txt-source5.txt each is a 1x10000 file with numbers 1-10000 randomly scattered for a ranking, each

Hello

C++

I have this code that takes 5 files, source1.txt-source5.txt each is a 1x10000 file with numbers 1-10000 randomly scattered for a ranking,

each column # is that ranks page #

I created code to assign a page number in a second row for each rank in the source1.txt-source5.txt files

I created the code to make a 6th file called combRank, this file combines the ranks from each sources columns. Ex all source1.txt-source5.txt sum of column 1 and so on

I defined a quicksort algorithm to find the ascending ordering of best rank (lowest value = best rank) to highest value. also, that specific column # aka page # gets sorted too

These ranks were sorted with the quicksort and like I said in ascending order, with a specific page number for that rank

I also used the same quicksort algorithm to sort each source1.txt-source5.txt

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

I need help creating an algorithm to find the number of inverses that each has source when compared to comRanks sorted array

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

Here is the code I have

#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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Object Databases The Essentials

Authors: Mary E. S. Loomis

1st Edition

020156341X, 978-0201563412

More Books

Students also viewed these Databases questions

Question

What are the determinants of cash cycle ? Explain

Answered: 1 week ago

Question

Question Can a self-employed person adopt a profit sharing plan?

Answered: 1 week ago