已知一个顺序表中的元素按元素值非递减有序排列,编写一个函数删除表中多余的值相同的元素。

如题所述

第1个回答  2013-09-26
int DelSameNode(stru *head)
{
stru *start,*nextnode;
int i = 0;
start = head;
while(start->next != NULL)
{
nextnode = start->next;
if(nextnode->a == start->a)
{
start->next = nextnode->next;
//严谨一点的话可以加一个释放操作;
free(next);
next = NULL;
}
else
{
start = start->next;
i++;
}
}
return i+1;
}

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网