Exemplo n.º 1
0
void SLDestroy(SortedListPtr list)
{
  node *p = list->base->next;
  // destroy every node in the list until reach the end of the list
  while (p != list->base) {
    p->prev->next = p->next;
    p->next->prev = p->prev;
    list->DF(p->data);
    free(p);
    p = list->base->next;
  }
  free(list->base);
  free(list);
}
Exemplo n.º 2
0
int SLRemove(SortedListPtr list, void *newObj)
{
  node *p = list->base->next;
  // find the first item equal to newObj
  while (p != list->base) {
    if (list->CF(newObj, p->data) == 0) {
      break;
    }
    p = p->next;
  }
  // if not find an item equal to newObj
  if (p == list->base)
    return 0;
  p->next->prev = p->prev;
  p->prev->next = p->next;
  //if there is no iterator "pointing" to this item, free it.
  if (p->refByItrCount == 0) {
    list->DF(p->data);
    free(p);
  }
  p->next = NULL;
  p->prev = NULL;
  return 1;
}