Answers for "delete the node with head in linked list"

C++
1

delete a head node in link list

void deleteNode(Node *head)
{
    Node* temp=head;
    if(head!=NULL)
    {
        head=head->next;
        delete temp;
    }
}
Posted by: Guest on March-26-2021
-1

delete node from linked list

void deleteNode(struct node **head, int key)
{
      //temp is used to freeing the memory
      struct node *temp;
     

      //key found on the head node.
      //move to head node to the next and free the head.
      if(*head->data == key)
      {
          temp = *head;    //backup the head to free its memory
          *head = (*head)->next;
          free(temp);
      }
    

}
Posted by: Guest on March-16-2022

Code answers related to "delete the node with head in linked list"

Browse Popular Code Answers by Language