text: #include <math.h>
  #include <stdio.h>
  #include <stdlib.h>
  
  #include "input_large.h"
  
  #define UNLIMIT
  
  /*struct my3DVertexStruct {
    int x, y, z;
    double distance;
  };*/
  
  int compare(const void* elem1, const void* elem2) {
    /* D = [(x1 - x2)^2 + (y1 - y2)^2 + (z1 - z2)^2]^(1/2) */
    /* sort based on distances from the origin... */
  
    double distance1, distance2;
  
    distance1 = (*((struct my3DVertexStruct*)elem1)).distance;
    distance2 = (*((struct my3DVertexStruct*)elem2)).distance;
  
    return (distance1 > distance2) ? 1 : ((distance1 == distance2) ? 0 : -1);
  }
  
  int main(void) {
    int i, count = 0;
  
    for (count = 0; count < sizeof(array) / sizeof(struct my3DVertexStruct);
         ++count)
      array[count].distance =
          sqrt(pow(array[count].x, 2) + pow(array[count].y, 2) +
               pow(array[count].z, 2));
  
    printf("\nSorting %d vectors based on distance from the origin.\n\n", count);
    qsort(array, count, sizeof(struct my3DVertexStruct), compare);
  
    for (i = 0; i < count; i++)
      printf("%d %d %d\n", array[i].x, array[i].y, array[i].z);
    return 0;
  }
  