|
@@ -8,6 +8,11 @@ static int ascending(const void *aa, const void *bb)
|
|
{
|
|
{
|
|
const DCELL *a = aa, *b = bb;
|
|
const DCELL *a = aa, *b = bb;
|
|
|
|
|
|
|
|
+ if (*a < *b)
|
|
|
|
+ return -1;
|
|
|
|
+ return (*a > *b);
|
|
|
|
+
|
|
|
|
+
|
|
if (Rast_is_d_null_value((DCELL *) a) && Rast_is_d_null_value((DCELL *) b))
|
|
if (Rast_is_d_null_value((DCELL *) a) && Rast_is_d_null_value((DCELL *) b))
|
|
return 0;
|
|
return 0;
|
|
|
|
|
|
@@ -22,26 +27,40 @@ static int ascending(const void *aa, const void *bb)
|
|
|
|
|
|
int sort_cell(DCELL * array, int n)
|
|
int sort_cell(DCELL * array, int n)
|
|
{
|
|
{
|
|
- int i;
|
|
|
|
|
|
+ int i, j;
|
|
|
|
|
|
- qsort(array, n, sizeof(DCELL), ascending);
|
|
|
|
|
|
+ j = 0;
|
|
|
|
+ for (i = 0; i < n; i++) {
|
|
|
|
+ if (!Rast_is_d_null_value(&array[i])) {
|
|
|
|
+ array[j] = array[i];
|
|
|
|
+ j++;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ n = j;
|
|
|
|
|
|
- for (i = 0; i < n; i++)
|
|
|
|
- if (Rast_is_d_null_value(&array[i]))
|
|
|
|
- break;
|
|
|
|
|
|
+ if (n > 0)
|
|
|
|
+ qsort(array, n, sizeof(DCELL), ascending);
|
|
|
|
|
|
- return i;
|
|
|
|
|
|
+ return n;
|
|
}
|
|
}
|
|
|
|
|
|
int sort_cell_w(DCELL(*array)[2], int n)
|
|
int sort_cell_w(DCELL(*array)[2], int n)
|
|
{
|
|
{
|
|
- int i;
|
|
|
|
|
|
+ int i, j;
|
|
|
|
|
|
- qsort(array, n, 2 * sizeof(DCELL), ascending);
|
|
|
|
|
|
+ j = 0;
|
|
|
|
+ for (i = 0; i < n; i++) {
|
|
|
|
+ if (!Rast_is_d_null_value(&array[i][0]) &&
|
|
|
|
+ !Rast_is_d_null_value(&array[i][1])) {
|
|
|
|
+ array[j][0] = array[i][0];
|
|
|
|
+ array[j][1] = array[i][1];
|
|
|
|
+ j++;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ n = j;
|
|
|
|
|
|
- for (i = 0; i < n; i++)
|
|
|
|
- if (Rast_is_d_null_value(&array[i][0]))
|
|
|
|
- break;
|
|
|
|
|
|
+ if (n > 0)
|
|
|
|
+ qsort(array, n, 2 * sizeof(DCELL), ascending);
|
|
|
|
|
|
- return i;
|
|
|
|
|
|
+ return n;
|
|
}
|
|
}
|