编写函数去掉重复元素c语言,【图片】想问一道链表题,如何删除重复元素【c语言吧】_百度贴吧...

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

# include "iostream.h"

# include "string.h"

# include "malloc.h"

# include "stdlib.h"

# define N 10

# define NULL 0

# define LEN sizeof(struct LNode)

struct LNode

{

char name[10];

int count;

struct LNode *next;

};

struct LNode *creat(void)

{

int i,n=0;

struct LNode *head,*p1,*p2;

cout<

head=NULL;

for(i=0;i

{

p1=(struct LNode *)malloc(LEN);

cin>>p1->name;

p1->count=0;

n=n+1;

if(n==1)

head=p1;

else

p2->next=p1;

p2=p1;

}

p2->next=NULL;

return(head);

}

void count(struct LNode *head)

{

struct LNode *p1=head,*p2=head;

while(p1!=NULL)

{

while(p2!=NULL)

{

if(strcmp(p1->name,p2->name)==0)

{

p1->count++;

}

p2=p2->next;

}

cout<name<count<

p2=head;

p1=p1->next;

}

}

struct LNode *sort(struct LNode *head,char *a)

{

struct LNode *p,*q;

int t;

for(p=head;p!=NULL;p=p->next)

{

for(q=p->next;q!=NULL;q=q->next)

{

if(p->countcount)

{

t=q->count;

strcpy(a,q->name);

q->count=p->count;

strcpy(q->name,p->name);

p->count=t;

strcpy(p->name,a);

}

}

}

return head;

}

struct LNode *del(struct LNode *head)

{

struct LNode *p1=head,*p2,*p3;

p2=p1->next;

p3=p1;

if(head!=NULL)

{

while(p1!=NULL)

{

p2=p1->next;

while(p2!=NULL)

{

if(strcmp(p2->name,p1->name)==0)

{

p3->next=p2->next;

p2=p2->next;

}

else

{

p3=p2;

p2=p2->next;

}

}

p1=p1->next;

p3=p1;

}

}

else

cout<

return head;

}

void print(struct LNode *head)

{

struct LNode *p;

cout<

p=head;

if(head==NULL)

cout<

else

{

while(p!=NULL)

{

cout<name<count<

p=p->next;

}

}

cout<

}

void main()

{

char a[10]=" ",*p=a;

struct LNode *head;

head=creat();

cout<

cout<

count(head);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值