Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define NUMELEMENTS 256
- /* function prototype, lets the compiler check types */
- int cmp(struct point * a,struct point * b)
- struct point{int x,y};
- int main(void){
- struct point array[NUMELEMENTS];
- /* add code to fill in the array etc. In the case you only use n elements replace NUMELEMENTS below with n*/
- qsort(array,NUMELEMENTS,sizeof(struct point),cmp);
- }
- /* Sorts on distance from origin */
- int cmp(struct point * a,struct point * b){
- long int dista,distb;
- dista = (a->x * a->x)+(a->y * a->y);
- distb = (b->x * b->x)+(b->y * b->y);
- return dista - distb;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement