Advertisement
Guest User

Untitled

a guest
Jun 10th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
BibTeX 0.57 KB | None | 0 0
  1. #define NUMELEMENTS 256
  2. /* function prototype, lets the compiler check types */
  3. int cmp(struct point * a,struct point * b)
  4.  
  5. struct point{int x,y};
  6.  
  7. int main(void){
  8.     struct point array[NUMELEMENTS];
  9.     /* add code to fill in the array etc. In the case you only use n elements replace NUMELEMENTS below with n*/   
  10.     qsort(array,NUMELEMENTS,sizeof(struct point),cmp);
  11. }
  12. /* Sorts on distance from origin */
  13. int cmp(struct point * a,struct point * b){
  14.     long int dista,distb;
  15.     dista = (a->x * a->x)+(a->y * a->y);
  16.     distb = (b->x * b->x)+(b->y * b->y);
  17.     return dista - distb;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement