Deleting a node from linked list in C

前端 未结 6 1977
醉酒成梦
醉酒成梦 2020-12-07 04:05

My problem is deleting a node from linked list.

I have two structs :

typedef struct inner_list 
{
 int count;
 char word[100];
 inner_list*next;
}          


        
6条回答
  •  鱼传尺愫
    2020-12-07 04:19

    m pointer is not set to any valid address before you dereference it and your program runs into undefined behavior.

    In order to fix your implementation use two pointers - one onto the current element and the other to the previous one and update both of them as you traverse the list. You'll have to treat cases with zero and oneelemenats as special - be careful.

提交回复
热议问题