Listing 1
// Delete a Node from a singly linked list.
void DeleteNode(LIST_NODE* pNodeToDelete) {
LIST_NODE** ppPrev = &gpRoot;
LIST_NODE* pNode = gpRoot;
// Pre: Node must not be NULL
assert(pNodeToDelete != NULL);
while (pNode != NULL) {
if (pNode == pNodeToDelete) {
*ppPrev = pNode->pNext;
free(pNode);
// Post: Node is deleted
assert(!zNodeExists(pNode));
return;
}
ppPrev = &(*ppPrev)->pNext;
pNode = pNode ->pNext;
}
// Pre: Node must exist in list. We reach this point
// only if Node is not present or the list is empty
assert(0);
}