Question

void Partition(int*Data,int low, int high, int& pivotpoint, int& CompareCount)
{
    int i ,j;
    // low is pivot ...

    int pivotitem = Data[low];
    j= low;
    for(i=low+1; i<=high;i++)
    {
        //data<pivot -> to low position
        if(Data[i] <pivotitem)
        {
            j++;
            int k = Data[i];
            Data[i] = Data[j];
            Data[j] = k;
        }
        CompareCount++;
    }
    //move pivot ,pivot position
    pivotpoint = j;
    int k = Data[j];
    Data[j]=Data[low];
    Data[low] = k;
}

here

I think the use of '&' is right.

But it didn't compile.

this is error and warning

error: expected ‘;’, ‘,’ or ‘)’ before ‘&’ token
warning: no newline at end of file

I don't know why this is happen~

Was it helpful?

Solution

In C, there is no call by reference, only call by value. Remove & and place *.

void Partition(int *Data, int low, int high, int *pivotpoint, int *CompareCount){...}

OTHER TIPS

Pass by reference, int&, is pure C++ and not available in C.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top