heapster-saw/examples/linked_list.c
/* Insert a value into a sorted list */
Insert a value into a sorted list
Insert a value into a sorted list
list64_t *sorted_insert (int64_t x, list64_t *l) {
  if (l == NULL) {
    list64_t *ret = malloc (sizeof (struct list64_t));
    ret->data = x;
    ret->next = NULL;
    return ret;
  } else if (x <= l->data) {
    list64_t *ret = malloc (sizeof (struct list64_t));
    ret->data = x;
    ret->next = l;
    return ret;
  } else {
    l -> next = sorted_insert (x, l->next);
    return l;
  }
}
list64_t * sorted_insert ( int64_t x , list64_t * l ) { if ( l == NULL ) { list64_t * ret = malloc ( sizeof ( struct list64_t ) ) ; ret -> data = x ; ret -> next = NULL ; return ret ; } else if ( x <= l -> data ) { list64_t * ret = malloc ( sizeof ( struct list64_t ) ) ; ret -> data = x ; ret -> next = l ; return ret ; } else { l -> next = sorted_insert ( x , l -> next ) ; return l ; } }
Insert a value into a sorted list
Insert a value into a sorted list