NODE* insertNode (NODE* head, NODE* pre, DATA item)
{
//Local Declaration
NODE* curr;
//Statement
if (!(curr = (NODE*)malloc(sizeof(NODE)))
printf("\amemory overflow in insert\n");
curr->data = item;
if (pre == NULL)
{
//inserting before first node or to empty list
curr->next = head;
head = curr;
}
else
{
//inserting in middle or at the end
curr->next = pre->next;
pre->next = curr;
}
return head;
}
这就是我根据正在阅读的书在现有列表中间插入节点的方式。但是,它并没有真正告诉我pre
这里是如何定义的(pre
指向前驱节点。)如何定义pre
指针以使其指向前驱节点?