Skip to content

Instantly share code, notes, and snippets.

@irrationnelle
Created November 5, 2015 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save irrationnelle/e426ac5dcf6261f21d44 to your computer and use it in GitHub Desktop.
Save irrationnelle/e426ac5dcf6261f21d44 to your computer and use it in GitHub Desktop.
I missed the condition in sentence 'while', that is 'Tail != NULL'. But I can not understand why I must add this condition sentence...
void SLL_RemoveNode(Node** Head, Node* Remove)
{
if((*Head)==NULL)
*Head = Remove->NextNode;
else
{
Node* Tail = *Head
while(Tail->NextNode != Remove)
{
Tail = Tail->NextNode;
}
Tail->NextNode = Remove->NextNode;
}
}
@irrationnelle
Copy link
Author

void SLL_RemoveNode(Node** Head, Node* Remove)
{
  if((*Head)==NULL)
    *Head = Remove->NextNode;
  else
  {
    Node* Tail = *Head
    while(Tail->NextNode != NULL && Tail->NextNode != Remove)
    {
      Tail = Tail->NextNode;
    }
    if(Tail->NextNode != NULL)
      Tail->NextNode = Remove->NextNode;
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment