4.3.4 Deletion

If a list is non-empty, then it must be deleted by unlinking and deallocating each node. Care must be taken so that the pointer to the rest is not destroyed before it can be copied or utilized.

The implementation is as follows:

void List_delete(struct List *pList)
{
  struct _Listnode *pTmp;

  pTmp = ((struct _List *)pList)->first;
  free(pList);
  while (pTmp)
  {
    struct _List next;
    next = pTmp->rest;
    free(pTmp);
    pTmp = next.first;
  }
}



Copyright © 2006-09-27 by Tak Auyeung