📄 删除重复数字.c
字号:
#include<stdio.h>
#include<malloc.h>
#define NULL 0
typedef struct node
{
int data;
struct node *next;
} node;
int n;
node * creat(void)
{
node *head;
node *p,*s;
n=0;
p=s=(node *)malloc(sizeof(node));
scanf("%d",&p->data);
head=NULL;
while (p->data!=0)
{n=n+1;
if(n==1) head=p;
else s->next=p;
s=p;
p=(node *)malloc(sizeof(node));
scanf("%d",&p->data);
}
s->next=NULL;
return (head);
}
void print( node *head)
{struct node *p;
p=head;
if(head!=NULL)
do
{
printf(" %d",p->data);
p=p->next;
}while(p!=NULL);
printf("\n");
}
node *delone( node* head)
{node *p,*q;
if(head!=NULL)
{
while(p->next!=NULL)
{if(p->data!=p->next->data) p=p->next;
else
{
q=p->next;
p->next=q->next;
free(q);
}
}}
return (head);
}
node * delsecond (node * head)
{
node *p,*q,*s;
p=head;
while(p->next!=NULL)
{ s=p;
while( s->next!=NULL)
{if(p->data==s->next->data)
{q=s->next;
s->next=s->next->next;
free(q);
continue;
}
s=s->next;
}
p=p->next;
}return (head);
}
main()
{
node * head ,*p,*q;
printf("\nqing shu ru you xu shu ju :\n");
head=creat();
printf("\nyou xu lian biao :\n");
print(head);
p= delone(head);
printf("\nsan chu hou de lian biao :\n");
print(p);
printf("\nqing shu ru wu xu shu ju :\n");
head=creat();
printf("\nwu xu lian biao :\n");
print(head);
q=delsecond(head);
printf("\nsan chu hou de lian biao :\n");
print(q);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -