0
y 값에 따라 x-y 좌표 구조체 포인터의 배열을 정렬하려면 qsort를 사용하려고하지만 q 정렬은 올바른 값을 비교하지 않습니다. 나는이 시점에서 당혹 스럽다. 내가 뭘 잘못하고 있는지 누가 알 수 있니?모든 0을 비교하는 qsort
분류 기능 :
23 int sortFunc(const void * firsti, const void * secondi){
24
25 const Coordinate* first = firsti;
26 const Coordinate* second = secondi;
27
28 printf("Comparing %f & %f\n", first->y, second->y);
29 if(first->y < second->y){ return 1;}
30 else if(first->y == second->y){ return 0; }
31 else{ return -1; }
32
33 }
인쇄 기능 :
13 void printArray(Coordinate * array[], int size){
14
15 int x;
16 for(x=0; x < size; x++){
17 printf("Point %i : %f | %f\n", x, array[x]->x, array[x]->y);
18 }
19
20 }
및 호출
79 qsort(pointArray, count, sizeof(Coordinate*), sortFunc);
80 printArray(pointArray, count);
수익률
Comparing 0.000000 & 0.000000
Comparing 0.000000 & 0.000000
Comparing 0.000000 & 0.000000
Comparing 0.000000 & 0.000000
Comparing 0.000000 & 0.000000
Comparing 0.000000 & 0.000000
Comparing 0.000000 & 0.000000
Point 0 : 103.253334 | -12.472327
Point 1 : -3.283118 | -3.101071
Point 2 : 9.289474 | -0.459975
Point 3 : 14.029107 | -11.844076
Point 4 : -6.465595 | 14.704790
Point 5 : -5.764663 | 8.882765
어떤 생각이 들었습니까? 당신이 Coordinate
구조체, 포인터Coordinate
에 구조체의 배열이 아닌 배열을 가지고있는 것처럼
예. 방금 가져 왔어. 감사 – Kdawg