已知顺序表中的元素按值非递减有序排列,编写一个函数删除表中多余的值相同的元素。(提示:值相同的元素
答案:1 悬赏:20 手机版
解决时间 2021-04-01 12:19
- 提问者网友:十年饮冰
- 2021-03-31 20:22
已知顺序表中的元素按值非递减有序排列,编写一个函数删除表中多余的值相同的元素。(提示:值相同的元素
最佳答案
- 五星知识达人网友:摆渡翁
- 2021-03-31 20:46
代码如下运行通过: #include #include #include typedef int ElemType; typedef struct Node { ElemType data; struct Node *next; }Node,*Sqlist; void IniList(Sqlist *L) { *L=(Sqlist)malloc(sizeof(Node)); (*L)->next=*L; } void Create_cLinkList(Sqlist L) { Node *s; int c; int flag=1; bool bl; L->data=NULL; L->next=NULL; while(flag) { bl=scanf("%d",&c); if(bl) { s=(Node *)malloc(sizeof(Node)); s->data=c; s->next=L->next; L->next=s; } else { flag=0; } } } void Treserve( Sqlist &L) { Node *p; Node *s; s=p=L->next; while(p->next!=NULL) { p=s; p=p->next; if(s->data==p->data) { if(p->next==NULL) s->next=NULL; else s->next=p->next; } else { s=p; } } } main() { Sqlist la; Node *p; Node *s; IniList(&la); printf("输入循环单链表A数据,按从小到大的顺序输入,输入$符号结束:\n"); Create_cLinkList(la); Treserve( la); s=la; p=la->next; while(s->next!=NULL) { printf("%d",p->data); s=p; p=p->next; } }
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯