【发布时间】:2014-08-15 12:40:02
【问题描述】:
我正在编写一个从 C++ 中的排序链表中删除重复值节点的方法。我正在尝试使用 Node* 而不是 void 返回类型,但由于 return 语句而面临错误。
我的方法代码..
Node* RemoveDuplicates(Node *head)
{
struct Node* current = head;
struct Node* next_next;
if(current == NULL)
return;
while(current->next != NULL)
{
if(current->data == current->next->data)
{
next_next = current->next->next;
free(current->next);
current->next = next_next;
}
else
{
current = current->next;
}
}
}
我收到的编译时错误消息..
solution.cc: In function 'Node* RemoveDuplicates(Node*)':
solution.cc:31:6: error: return-statement with no value, in function returning 'Node*' [-fpermissive]
return ;
^
【问题讨论】:
-
即使你的函数没有返回任何东西,你为什么还要使用
Node *? -
错误信息很清楚,阅读一下。
-
你正在用 C 编写。
标签: c++ pointers linked-list return