All pastes #585818 Raw Edit

plutonas

public c v1 · immutable
#585818 ·published 2007-06-23 13:59 UTC
rendered paste body
void mysort(void){  struct qentry *a[3*lines];  int j = 0;  STAILQ_INIT(&qhead);  struct entry *np; // ayto tha diatrexei ta tmimata sto linked list  struct qentry *pnp, *place;  place = malloc(sizeof(struct qentry));  LIST_FOREACH(np, &head, entries){     pnp = malloc(sizeof(struct qentry));    pnp->fatherline = malloc (sizeof(struct entry)); //ayto den eimai sigouros an einai peritto i oxi        pnp->pnt.x = np->myline.end2->x;    pnp->pnt.y = np->myline.end2->y;    pnp->fatherline = np;    a[j] = pnp; j++;    //an to queue einai adeio, vazoume ena stoixeio alloios vriskoume tin thesi kai to topothetoume meta ap'aytin    if(STAILQ_EMPTY(&qhead)){      STAILQ_INSERT_HEAD(&qhead, pnp, qentries);      i++;    }    else{      place = findplace(pnp, 0, i-1);      if(place != pnp){  //otan theloume na valoume ena sto head, i diadikasia ginetai mesa stin findplace opote den kanoume tpt kai epistrefoume n1 gia na kanoume edo ton elegxo	STAILQ_INSERT_AFTER(&qhead, place, pnp, qentries);	i++;      }    }  }  //  edo na kano kai mia sort  mergesort(a, j-1, sizeof(struct qentry),(int (*)(const void *, const void *)) heap_cmp);  int k = 0;  while(k<j){    printf("%d %d\n", a[k]->pnt.x, a[k]->pnt.y);    k++;}}static int heap_cmp(struct qentry * e1, struct qentry * e2) {   if(e1->pnt.y == e2->pnt.y)    return e1->pnt.x - e2->pnt.x;  else    return e1->pnt.y - e2->pnt.y;}