【发布时间】:2020-10-13 14:14:38
【问题描述】:
struct someEvent
{
int id;
struct someEvent *prev;
struct someEvent *next;
} * someEvent;
struct someEvent *someEventQueue = NULL;
int main(){
//There is some conditions. If passing all of conditions then It is inserted to someEventQueue.
struct someEvent **curr = &someEventQueue;
if ((*curr) != NULL)
{
while ((*curr) != NULL)
{
//After some processes, I want to delete (*curr)
if ((*curr)->prev == NULL && (*curr)->next == NULL)
{
//I don't know how to do this........................
}
if ((*curr)->prev != NULL)
{
(*curr)->next->prev = (*curr)->prev;
}
if ((*curr)->next != NULL)
{
(*curr)->prev->next = (*curr)->next;
}
curr = &(*curr)->next;
}
}
}
我想删除出现在 someEventQueue 中的节点。 someEventQueue 是双链表。我试图制作一个删除节点代码。但是,我失败了。我不知道为什么,但它返回分段错误。如何解决这个问题?
【问题讨论】:
-
请提供minimal reproducible example。此外,从列表中删除节点并不是一个新问题。尝试看看是否有任何关于此的问题可以用来解决您的问题。
-
你是用一张纸和一支铅笔做的吗?
标签: c linked-list doubly-linked-list