Deleting a middle node from a single linked list when pointer to the previous node is not available

前端 未结 24 1332
陌清茗
陌清茗 2020-11-29 20:42

Is it possible to delete a middle node in the single linked list when the only information available we have is the pointer to the node to be deleted and not the pointer to

24条回答
  •  [愿得一人]
    2020-11-29 21:09

    void delself(list *list)
    {
       /*if we got a pointer to itself how to remove it...*/
       int n;
    
       printf("Enter the num:");
    
       scanf("%d",&n);
    
       while(list->next!=NULL)
       {
           if(list->number==n) /*now pointer in node itself*/
           {
               list->number=list->next->number;
               /*copy all(name,rollnum,mark..) data of next to current, disconect its next*/
               list->next=list->next->next;
           }
           list=list->next;
       }
    }
    

提交回复
热议问题