完成函数dubdel的编写,该函数删除单向链表中的重复结点,如果链表中存在重复结点(除next指针外的其它数据成员的值相同)时,保留离链首最近的结点。
样例输入:
5
1 2 3 2 4
样例输出:
1 2 3 4
#include<iostream>
#include <string>
using namespace std;
struct Node
{
int num;
Node *next;
};
Node * dubdel(Node *head)
{
int a[1000],n=0,i;
Node *cur=head,*pre=NULL;
while(cur