#include<iostream>
#include<stdlib.h>
using namespace std;
typedef int ElemType;
typedef struct LNode
{
ElemType data;
struct LNode *next;
}LNode,*LinkList;
void show(LinkList L)
{
LinkList p;
p=L->next;
while(p)
{
if(p->next==NULL)
cout<<p->data<<endl;
else
cout<<p->data<<" ";
p=p->next;
}
}
void CreateList_L(LinkList &L,int n)
{
LinkList p;
p=new LNode;
L=new LNode;
L->next=NULL;
LinkList q;
q=new LNode;
cin>>q->data;
q->next=NULL;
L->next=p;
for(int i=2;i<=n;i++)
{
p=new LNode;
cin>>p->data;
p->next=q;
L->next=p;
q=p;
}
cout<<n<<endl;
show(L);
}
void deletenum(LinkList &L,int n)
{
LinkList p,p1,p2;
p=L;
while(p->next!=NULL)
{
p1=p;
p2=p->next;
while(p2!=NULL)
{
if(p->data==p2->data)
{
p1->next=p2->next;
p2=p2->next;
n--;
}
else
{
p1=p1->next;
p2=p2->next;
}
}
p=p->next;
}
cout<<n<<endl;
show(L);
}
int main()
{
LinkList L;
int n;
cin>>n;
CreateList_L(L,n);
deletenum(L,n);
return 0;
}
/***************************************************
User name: TJRAC6015203228魏杰
Result: Accepted
Take time: 0ms
Take Memory: 156KB
Submit time: 2016-11-01 13:59:38
****************************************************/
sdut2122数据结构实验之链表七:单链表中重复元素的删除
最新推荐文章于 2023-03-09 21:23:42 发布