I'm writing some code in C++ to do the quick sort algorithm to sort an array of integers. I have my complete code here:
void swap(int A[], int x, int y)
{
int tmp;
tmp=A[x];
A[x]=A[y];
A[y]=tmp;
}
int partition(int A[], int start, int stop)
{
int big=start;
int pivot=A[stop];
for(int i=start; i<stop; i++)
{
if(A[i]<=pivot)
{
swap(A, i, big);
big++;
}
}
swap(A, big, stop);
return big;
}
void quick_Sort_Helper(int A[], int start, int stop)
{
//base cases
if(stop<=start)
{return;}
if(start+1==stop)
{
if(A[start]>A[stop])
{swap(A, start, stop);}
return;
}
//recursive cases
int pivot=partition(A,start, stop);
quick_Sort_Helper(A,start, pivot-1);
quick_Sort_Helper(A, pivot, stop);
}
void quick_Sort(int A[])
{
quick_Sort_Helper(A,0, A.size()-1);
}
I get an error when compiling the program on the line where I call A.size(). The error reads as follows:
error: request for member ‘size’ in ‘A’, which is of non-class type ‘int*’
I don't understand because the size() function of an array is supposed to return an integer with the length/ number of elements in the array.