Exemplo n.º 1
0
int main(int argc, char **argv) {
  int                           i,a;
  dllist                        *l, *the_list;
  struct sglib_dllist_iterator  it;

  the_list = NULL;
  for (i=1; i<argc; i++) {
    sscanf(argv[i],"%d", &a);
    l = malloc(sizeof(dllist));
    l->i = a;
    sglib_dllist_add(&the_list, l);
  }
  // sort the list
  sglib_dllist_sort(&the_list);
  // print the list
  for(l=sglib_dllist_get_first(the_list); l!=NULL; l=l->ptr_to_next) printf("%d ", l->i);
  printf("\n");
  // print the list in reversed direction
  for(l=sglib_dllist_get_last(the_list); l!=NULL; l=l->ptr_to_previous) printf("%d ", l->i);
  printf("\n");
  // free the list
  for(l=sglib_dllist_it_init(&it,the_list); l!=NULL; l=sglib_dllist_it_next(&it)) {
    free(l);
  }
  return(0);
}
Exemplo n.º 2
0
int benchmark()
{
  volatile int cnt=0;
  dllist *l, *last, *the_list;
  struct sglib_dllist_iterator  it;
  int i;

  the_list = NULL;
  for(i = 0 ;i<100; ++i)
  {
    l = malloc(sizeof(dllist));
    l->i = array[i];
    sglib_dllist_add(&the_list, l);
  }

  sglib_dllist_sort(&the_list);

  last = sglib_dllist_get_first(the_list);
  for(l=sglib_dllist_get_first(the_list); l!=NULL; l=l->ptr_to_next)
  {
    l->i = last->i;
    last = l;
  }

  for(l=sglib_dllist_get_last(the_list); l!=NULL; l=l->ptr_to_previous)
  {
    l->i = last->i;
    last = l;
  }

  for(l=sglib_dllist_it_init(&it,the_list); l!=NULL; l=sglib_dllist_it_next(&it))
  {
    cnt += l->i;
    free(l);
  }

  return cnt;
}