This is a very basic question, and I think I'm still misunderstanding something very basic.. In my work, I'm trying to use a code someone else wrote in the past and seeing an error I'm having trouble to solve.
Below is the code. I get error in function Partition2. in line float pivot = arr[left][0];
. I tried float pivot = *(*(arr+left)+0);
but it's the same. I know arr
is of type float[300][1]. How can I use the function with smallest modification?
in test.c
#define post_nms_topN 300
float unit_bbox_pred[post_nms_topN][4];
float unit_cls_prob[post_nms_topN][1];
...
main()
{
...
QuickSort2((float **)unit_cls_prob,0,post_nms_topN-1,(float **)unit_bbox_pred);
..
}
in QuickSort2.c
...
int Partition2(float **arr, int left, int right, float **prop)
{
float pivot = arr[left][0]; // <=== seg. fault
//float pivot = *(*(arr+left)+0);
int low = left+1;
int high = right;
while(low <= high)
{
while(pivot <= arr[low][0] && low <= right)
low++;
while(pivot >= arr[high][0] && high >= (left+1))
high--;
if(low <= high)
Swap2(arr, low, high, prop);
}
Swap2(arr, left, high, prop);
return high;
}
void QuickSort2(float **arr, int left, int right, float **prop)
{
int pivot;
if(left <= right)
{
pivot = Partition2(arr, left, right, prop);
QuickSort2(arr, left, pivot-1, prop);
QuickSort2(arr, pivot+1, right, prop);
}
}