重复元素的删除问题
来源:互联网 发布:知乎周刊 编辑:程序博客网 时间:2024/05/22 02:31
代码:
#include<stdio.h>
#include<malloc.h>struct node
{
int data;
struct node *next;
};
struct node *creat(int n)
{
struct node *head,*p;
head=(struct node*)malloc(sizeof(struct node));
head->next=NULL;
for(int i=0;i<n;i++)
{
p=(struct node*)malloc(sizeof(struct node));
scanf("%d",&p->data);
p->next=NULL;
p->next=head->next;
head->next=p;
}
return head;
}
void print(struct node *h)
{
struct node *p=h->next;
while(p!=NULL)
{
if(p->next==NULL)
printf("%d\n",p->data);
else
printf("%d ",p->data);
p=p->next;
}
}
struct node *chazhao(struct node *head,int n)
{
struct node *p,*q,*h;
h=head->next;
while(h!=NULL)
{
p=h;
while(p->next!=NULL)
{
if(p->next->data==h->data)
{
q=p->next;
p->next=q->next;
free(q);
n--;
}
else
p=p->next;
}
h=h->next;
}
printf("%d\n",n);
return head;
}
int main()
{
int n;
scanf("%d",&n);
struct node *head1,*head2;
head1=creat(n);
printf("%d\n",n);
print(head1);
head2=chazhao(head1,n);
print(head2);
return 0;
}
0 0
- 重复元素的删除问题
- 重复元素的删除
- 重复元素的删除
- 删除单链表中重复的元素
- 删除单链表中重复的元素
- 删除单链表中重复的元素
- 删除链表中重复的元素
- 删除数组的重复元素
- 删除单链表中重复的元素
- 单链表中重复元素的删除
- 单链表中重复元素的删除
- 单链表中重复元素的删除
- 单链表中重复元素的删除
- 单链表中重复元素的删除
- 删除链表中重复的元素
- 单链表中重复元素的删除
- 删除链表中重复的元素
- 删除链表中重复的元素
- 使用 CXF 做 webservice 简单例子
- LeetCode 263. Ugly Number
- 【多线程】三种方案实现多线程之间相互协作的通信
- 【HDU 1950】Bridging signals(LIS算法求最长上升子序列)
- Failed to instantiate * using constructor public * with arguments **
- 重复元素的删除问题
- Android基本控件复习笔记(一)
- 【CodeForces】371C - Hamburgers(二分)
- c#之用StreamWriter追加写文件
- Ubuntu上搭建samba服务器并远程挂载
- HeadFirst设计模式读书笔记——简单工厂模式
- 开发一个文件搜索程序
- 进阶项目4-体重监测器
- Codeforces 439D Devu and his Brother