All pastes #595021 Raw Edit

plutonas

public text v1 · immutable
#595021 ·published 2007-06-29 08:10 UTC
rendered paste body
include<stdio.h>

struct point{
  int x;
  int y;
};

struct subtest{
  struct point pnt;
};

struct test{
  int i;
  struct test *ntest;
  struct subtest *justtotest;
};


static int cmp(struct test *e1, struct test *e2) { 
  return e1->i - e2->i;
}


int main(void){
  struct test **a;
  struct test *k, *l, *m;

  a = malloc(4*(sizeof(struct test *) + sizeof(struct subtest *) + sizeof(struct test *)));

  k = malloc(sizeof(struct test));
  l = malloc(sizeof(struct test));
  m = malloc(sizeof(struct test));

  k->i = 1;
  l->i = 2;
  m->i = 3;

  k->justtotest->pnt.x = 4;

  k->ntest = l;
  l->ntest = m;
  m->ntest = k;

  a[0] = k;
  a[1] = l;
  a[2] = m;

  a[3] = a[0];
  a[0] = a[2];
  a[2] = a[3];

 mergesort(a, 3, sizeof(struct test *),(int (*)(const void *, const void *)) cmp);

  int j;
  for(j = 0; j<3; j++){
    printf("%d\n", a[j]->i);
    printf("\t%d\n", a[j]->ntest->i);
  }
}