求助-C数据结构
/* Note:Your choice is C IDE */#include "stdio.h"
#include<stdlib.h>
typedef struct node
{
int date;
struct node *next;
}node;
void sclist (node *h)
{
node *p,*r,*q,*s;
p=h->next;
r=h->next;
q=h->next;
p=p->next;
while(p!=NULL)
{
while(p!=NULL)
{
if(q->date==p->date)
{
r->next=p->next;
s=p;
p=p->next;
free(s);
r=p;
p=r->next;
}
else
{
r=r->next;
p=p->next;
}
}
q=q->next;
r=q;
p=r->next;
}
}
void input(node *h)
{
node *p,*r;
int x;
r=h;
printf("请输入你的数据:");
scanf("%d",&x);
while(x!=-999)
{
p=(node *)malloc(sizeof(node));
p->date=x;
r->next=p;
p->next=NULL;
r=p;
scanf("%d",&x);
}
}
void putlist(node *h)
{
node *p;
p=h->next;
while(p!=NULL)
{
printf("%d ",p->date);
p=p->next;
}
}
void main()
{
node *h;
h=(node *)malloc(sizeof(node));
h->next=NULL;
input(h);
putlist(h);
sclist(h);
putlist(h);
}
想实现; 删除一组数中重复的数
例如:
输入:1 2 1 2 2 2 2 5
输出; 1 2 5