| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 990 人关注过本帖
标题:大家帮忙看看这个插入的操作````
只看楼主 加入收藏
guitarliukai
Rank: 1
等 级:新手上路
帖 子:73
专家分:0
注 册:2004-12-5
收藏
 问题点数:0 回复次数:15 
大家帮忙看看这个插入的操作````

#include <stdio.h> #define len sizeof(struct a) #include <malloc.h>

typedef struct b {char lk; struct b *next ; }a,*Linklist;

void output(a *head){ a *p; p=head; while (p != NULL)

{ printf("%c ",p->lk); p=p->next; } printf("\n"); }

Linklist Deletechar(a *head) {a *p,*q,*o; char ch; o=q=p=head; printf("\ninput deleted letter:"); scanf("%c",&ch); while(ch != '0') { q=p=head;

while(p->lk != ch && p != NULL) {q=p; p=p->next;} if(p==head) { head=head->next;free(p); } else { if(p->lk == ch)

{ q->next=p->next; free(p) ; } else printf("can't find it "); } printf("deleted ago is :\n"); output(head); printf("plese input delete char:\n"); fflush(stdin);/*在此加上清流函数 */ scanf("%c",&ch); } return o; } Linklist insert(a *head) { a *p,*q,*s,*o; char ch; o=q=p=head; printf("\ninput insert letter:"); fflush(stdin); scanf("%c",&ch); while(ch != '0') { q=p=head; while(p->lk < ch && p != NULL) { q=p; p=p->next;}

if(p == head) { if(p->lk==ch) {printf("it is exist !!!!\n");} else

{ if((s=(a *)malloc(sizeof(a)))==NULL) exit(1); /*s=(struct a *) malloc(len);*/ s->lk=ch; s->next=p; head=p=s;} } else { if(p->lk != ch) { if((s=(a *)malloc(sizeof(a)))==NULL) exit(1); /*s=(struct a *) malloc(len);*/ s->lk=ch; s->next=p; q->next=s; q=p=head;} else { printf("888 it is exist\n"); q=p=head;}

} printf("inserted:\n"); output(head); printf("plese input insert char:\n"); fflush(stdin);/*在此加上清流函数 */ scanf("%c",&ch); } return head;

}

main() {struct a *head,*p,*q,*s; int i; if((p=(a *)malloc(sizeof(a)))==NULL) exit(1); head=p; for(i=1;i<=25;i++) { (p->lk)=('a'+i-1); if((p->next=(a *)malloc(sizeof(a)))==NULL) exit(1); p=p->next;

} p->lk='z'; p->next=NULL; p=head; printf("26 char is :\n"); output(head); Deletechar(head); insert(head);

} 插入操作有问题,大家看看怎么改一下````谢谢了``` 删除一个字母后,在插就死循环`````

搜索更多相关主题的帖子: include letter 
2005-04-21 15:15
lycnsc
Rank: 1
等 级:新手上路
帖 子:243
专家分:0
注 册:2005-3-27
收藏
得分:0 
#define len sizeof(struct a)
要是我没记错的话,  你这句实际上是将sizeof(struct 替换len, 而不是sizeof(struct a)替换len.  因为sizeof(struct a)
中有空格!
2005-04-21 15:20
guitarliukai
Rank: 1
等 级:新手上路
帖 子:73
专家分:0
注 册:2004-12-5
收藏
得分:0 
我 改成 #define len sizeof(struct len) 后

还是死循环~~~~~~~`

我录的歌 http://1680279./ 我现在打不开了????
2005-04-21 15:26
guitarliukai
Rank: 1
等 级:新手上路
帖 子:73
专家分:0
注 册:2004-12-5
收藏
得分:0 

斑竹运行这个 带头节点的 都没问题```````` #include<stdio.h> #include<malloc.h> #include<stdlib.h> typedef struct Node{ char data; struct Node *next; }SLNode,*Linklist; void output(SLNode *head){ SLNode *p; p=head; while(p->next!=NULL){ printf("%c ",p->next->data); p=p->next; } printf("\n"); } Linklist Deletechar(SLNode *head) { SLNode *p,*q; char ch; p=head; printf("please input delete char(The zero is over ! ):\n"); scanf("%c",&ch); while(ch!='0') { p=head; while(p->next!=NULL&&p->next->data<ch) p=p->next; if(p->next->data!=ch) printf("No fine the delete char\n"); else { q=p->next; p->next=q->next; free(q); q=NULL; } printf("deleted:\n"); output(head); printf("plese input delete char:\n"); fflush(stdin);/*在此加上清流函数 */ scanf("%c",&ch); } return head; } Linklist insert(SLNode *head) { SLNode *p,*q; char ch; printf("please input your char(The zero is over ! ):\n"); scanf("%c",&ch); while(ch!='0') { p=head; while(p->next!=NULL&&p->next->data<ch) p=p->next; if(p->next->data==ch) printf("list have a char\n"); else { if((q=(SLNode *)malloc(sizeof(SLNode)))==NULL)exit(1); q->data=ch; q->next=p->next; p->next=q; } printf("inserted:\n"); output(head); printf("plese input insert char:\n"); fflush(stdin);/*在此加上清流函数 */ scanf("%c",&ch); } return head;

} main() {SLNode *head,*p,*q; int i; char exit2;

if((head=(SLNode *)malloc(sizeof(SLNode)))==NULL) exit(1); head->next=NULL; p=head; for(i=0;i<26;i++) { if((q=(SLNode *)malloc(sizeof(SLNode)))==NULL)exit(1); (q->data)=('a'+i); q->next=NULL; p->next=q; p=q; q=NULL; } p=head; printf("26 char:\n"); output(head); printf("\n"); do{ Deletechar(head); insert(head); printf("exit is input k :"); fflush(stdin); scanf("%c",&exit2); } while(exit2 != 'k') ; }


我录的歌 http://1680279./ 我现在打不开了????
2005-04-21 15:31
lycnsc
Rank: 1
等 级:新手上路
帖 子:243
专家分:0
注 册:2005-3-27
收藏
得分:0 
其他有错没我不知道!但第二句就错了,你改为int length=sizeof(struct len)试试!
2005-04-21 15:32
guitarliukai
Rank: 1
等 级:新手上路
帖 子:73
专家分:0
注 册:2004-12-5
收藏
得分:0 
你说的哪个,哪个第二句````````````

我录的歌 http://1680279./ 我现在打不开了????
2005-04-21 15:37
lycnsc
Rank: 1
等 级:新手上路
帖 子:243
专家分:0
注 册:2005-3-27
收藏
得分:0 
晕!正数第二句,就是#define len sizeof(struct a)这句
2005-04-21 15:42
guitarliukai
Rank: 1
等 级:新手上路
帖 子:73
专家分:0
注 册:2004-12-5
收藏
得分:0 
改成 int length=sizeof(struct len) 都没法编译``````

晕啊`````

我录的歌 http://1680279./ 我现在打不开了????
2005-04-21 15:46
lycnsc
Rank: 1
等 级:新手上路
帖 子:243
专家分:0
注 册:2005-3-27
收藏
得分:0 
晕!length是我随便起的名字! #define 的格式是#define+空格+语句(中间不能有空格)+空格+语句(中间不能有空格) 总共只能有2个空格,你看你的#define len sizeof(struct a)有3个空格!
2005-04-21 15:52
guitarliukai
Rank: 1
等 级:新手上路
帖 子:73
专家分:0
注 册:2004-12-5
收藏
得分:0 
那 怎么没提示出错啊``````?

我看别人的的是这啊`````

不是这里的错``````````

我录的歌 http://1680279./ 我现在打不开了????
2005-04-21 15:58
快速回复:大家帮忙看看这个插入的操作````
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024678 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved