#include
#include
struct node
{
int data;
struct node *next;
};
struct node *creat(int n)
{
struct node *head,*p;
int i;
head=(struct node *)malloc(sizeof(struct node));
head->next=NULL;
for(i=0;i
data);
p->next=head->next;
head->next=p;
}
return head;
};
void P(struct node *head)
{
struct node *p;
p=head->next;
while(p)
{
printf(p->next?"%d ":"%d\n",p->data);
p=p->next;
}
}
struct node *Del(struct node *head,int n)
{
int ss=n;
struct node *q,*p,*l;
p=head->next;
l=p;
while(p)
{
l=p;
q=p->next;
while(q)
{
if(q->data==p->data)
{
l->next=q->next;
free(q);
q=l->next;
ss--;
}
else
{
q=q->next;
l=l->next;
}
}
p=p->next;
}
printf("%d\n",ss);
return head;
} ;
int main()
{
struct node *head;
int n;
while(~scanf("%d",&n))
{
head=(struct node *)malloc(sizeof(struct node));
head=creat(n);
printf("%d\n",n);
P(head);
head=Del(head,n);
P(head);
}
}empty
数据结构上机测试2-2:单链表操作B
最新推荐文章于 2016-07-23 08:38:04 发布