C++ Sorting the “percentage” of two paired integer arrays

后端 未结 3 477
鱼传尺愫
鱼传尺愫 2021-01-27 11:54

I have a program with 2 \"paired\" integer arrays newNumerator[ ], and newDenominator[ ] which both have 9 integers in them. I wrote a function that sorts them in ascending ord

3条回答
  •  星月不相逢
    2021-01-27 12:38

    You said:

    I have a program with 2 "paired" integer arrays newNumerator[ ], and newDenominator[ ]

    Yet your function defined as:

    void sortData(int *newNumerator[], int *newDenominator[], int newSize) 
    

    I think that should be:

    void sortData(int newNumerator[], int newDenominator[], int newSize) 
    

    If that is indeed the case, then the lines:

    temp1 = *newNumerator[count];
    *newNumerator[count] = *newNumerator[count + 1];
    *newNumerator[count + 1] = temp1;
    
    temp2 = *newDenominator[count];
    *newDenominator[count] = *newDenominator[count + 1];
    *newDenominator[count + 1] = temp2;
    

    need to be:

    temp1 = newNumerator[count]; // Remove the *
    newNumerator[count] = newNumerator[count + 1];
    newNumerator[count + 1] = temp1;
    
    temp2 = newDenominator[count];
    newDenominator[count] = newDenominator[count + 1];
    newDenominator[count + 1] = temp2;
    

提交回复
热议问题