这是我相信会是更好的方式。什么是更好的方法?
int main()
{
node *head;
insertAfter(&head, 14, 12);
}
void insertAfter(node **head, int item, int after)
{
node *ptr, *loc;
loc = searchUnsorted(*head, after); //copy of *head passed
if(loc == (node *) NULL)
return;
ptr = (node*)malloc(sizeof(node));
ptr -> info = item;
ptr -> next = loc -> next;
loc -> next = ptr;
}
这就是我的老师认为的那样。
int main()
{
node *head;
insertAfter(head, 14, 12);
}
void insertAfter(node *head, int item, int after)
{
node *ptr, *loc;
loc = searchUnsorted(head, after); //copy of *head passed
if(loc == (node *) NULL)
return;
ptr = (node*)malloc(sizeof(node));
ptr -> info = item;
ptr -> next = loc -> next;
loc -> next = ptr;
}
你们两个都没有设置让我打电话给B.S的头部。那其中之一是来自你的老师。无论如何。不清楚你是什么样的人)试图做什么和b)问题是什么。 – John3136
你所做的唯一改变是将指针传递给指针而不是指针?或者我错过了什么?你能详细说明你为什么认为你的版本更好?对我来说,没有任何性能提升,代码的可读性不高。 – Outshined
@Caribou你没有错过任何东西。我只是认为如果我只是通过地址而不是副本,情况会好一些。这就是它的工作原理,不是吗? –