| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1621 人关注过本帖
标题:大家帮我看看 26个字母删除的操作,怎么只能删除一个呀``???
只看楼主 加入收藏
神vLinux飘飘
Rank: 13Rank: 13Rank: 13Rank: 13
来 自:浙江杭州
等 级:贵宾
威 望:91
帖 子:6140
专家分:217
注 册:2004-7-17
收藏
得分:0 
是地,哈哈,如果你自己也那么认为的话~

淘宝杜琨
2005-04-09 12:16
tjl2006tjl
Rank: 1
等 级:新手上路
帖 子:37
专家分:0
注 册:2004-12-16
收藏
得分:0 
学习成绩不好是不是不能学C啊?

2005-04-09 16:10
guitarliukai
Rank: 1
等 级:新手上路
帖 子:73
专家分:0
注 册:2004-12-5
收藏
得分:0 

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

struct a {char lk; struct a *next ; };

main() {struct a *head,*p,*q; int i; char ch;

head=p=(struct a *) malloc(len);

for(i=1;i<=26;i++) {(p->lk)=('a'+i-1); p->next=(struct a *)malloc(len); p=p->next;

} p->next=NULL;

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

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

p=head; printf("input deleted letter"); scanf("%c",&ch); while(p->lk != ch && p->next != NULL) p=p->next; q=p; p=q->next; free(q); while (p->next != NULL)

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

} 大家看看这段程序`````` 我想输入 b后 显示为 a,c,d,e,f,g````````````````z 可是,却是 c,d,e,f,g,h,````````````````z 该怎么改改啊```


我录的歌 http://1680279./ 我现在打不开了????
2005-04-09 16:32
空前
Rank: 1
等 级:新手上路
帖 子:1146
专家分:0
注 册:2004-5-11
收藏
得分:0 

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

struct a {char lk; struct a *next ; };

main() {struct a *head,*p,*q; int i; char ch;

head=p=(struct a *) malloc(len);

for(i=1;i<=26;i++) {(p->lk)=('a'+i-1); p->next=(struct a *)malloc(len); p=p->next;

} p->next=NULL;

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

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

q=p=head; printf("input deleted letter"); scanf("%c",&ch); while(p->lk!=ch&&p) {q=p;p=p->next;} if(p==head) head=head->next; else q->next=p->next; free(p); p=head;

while (p->next!=NULL)

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

}

[此贴子已经被作者于2005-4-9 17:15:10编辑过]


2005-04-09 17:13
guitarliukai
Rank: 1
等 级:新手上路
帖 子:73
专家分:0
注 册:2004-12-5
收藏
得分:0 
我写的程序没头接点``

我录的歌 http://1680279./ 我现在打不开了????
2005-04-09 17:34
daxuediannao
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2005-4-5
收藏
得分:0 
   好复杂啊

我就是我 我在努力
2005-04-09 18:00
激情依旧
Rank: 1
等 级:新手上路
威 望:2
帖 子:524
专家分:0
注 册:2005-4-4
收藏
得分:0 

//数组写的 不是本人写的。 是guitarliukai他同学写的。我和guitarliukai也写了链表的 在下一楼呢 //我认为他写的很好。程序的健壮性非常好。所以我在次帮他同学发表出来。希望他勿怪。 #include <stdio.h>

#include <string.h>

main()

{ char str[27]="abcdefghijklmnopqrstuvwxyz";

char ch[2];

int i,j;

printf("\n%s",str);

printf("\ndelete(if exit ,enter 0):");

scanf("%s",ch);

while(ch[0]!='0')

{ j=-1;

for(i=0;str[i]!='\0';i++)

if (ch[0]==str[i])

{j=i;break;}

if (j!=-1)

{ while(str[i+1]!='\0')

{ str[i]=str[i+1];

i++;

}

str[i]='\0';

printf("\n%s\n",str);

}

else

printf("\nno find %c",ch[0]);

printf("\ndelete(if exit,enter 0):");

scanf("%s",ch);

}

printf("\ninsert(if exit,enter 0):");

scanf("%s",ch);

while(ch[0]!='0')

{ if ((ch[0]<'a')||(ch[0]>'z')) printf("\nIt is not letter");

else

{

for(i=0;str[i]!='\0';i++)

{ if(ch[0]>str[i]) continue;

else

{ if(ch[0]==str[i]) {printf("have exist"); break;}

else

{ j=strlen(str);

str[j+1]='\0';

for(;j>i;j--)

str[j]=str[j-1];

str[j]=ch[0];

printf("\n%s",str);

break;

}

}

}

}

printf("\ninsert(if exit,enter 0):");

scanf("%s",ch);

}

}


生是编程人!!!!死是编程鬼!!!!颠峰人生!!!焚尽编程!!! 爱已严重死机!情必须重新启动!情人已和服务器断开连接!网恋也需要重新拨号!-----激情依旧
2005-04-09 22:52
激情依旧
Rank: 1
等 级:新手上路
威 望:2
帖 子:524
专家分:0
注 册:2005-4-4
收藏
得分:0 

//数组写的 不是本人写的。 是guitarliukai他同学写的。我和guitarliukai也写了链表的 在下一楼呢 //我认为他写的很好。程序的健壮性非常好。所以我在次帮他同学发表出来。希望他勿怪。 #include <stdio.h>

#include <string.h>

main()

{ char str[27]="abcdefghijklmnopqrstuvwxyz";

char ch[2];

int i,j;

printf("\n%s",str);

printf("\ndelete(if exit ,enter 0):");

scanf("%s",ch);

while(ch[0]!='0')

{ j=-1;

for(i=0;str[i]!='\0';i++)

if (ch[0]==str[i])

{j=i;break;}

if (j!=-1)

{ while(str[i+1]!='\0')

{ str[i]=str[i+1];

i++;

}

str[i]='\0';

printf("\n%s\n",str);

}

else

printf("\nno find %c",ch[0]);

printf("\ndelete(if exit,enter 0):");

scanf("%s",ch);

}

printf("\ninsert(if exit,enter 0):");

scanf("%s",ch);

while(ch[0]!='0')

{ if ((ch[0]<'a')||(ch[0]>'z')) printf("\nIt is not letter");

else

{

for(i=0;str[i]!='\0';i++)

{ if(ch[0]>str[i]) continue;

else

{ if(ch[0]==str[i]) {printf("have exist"); break;}

else

{ j=strlen(str);

str[j+1]='\0';

for(;j>i;j--)

str[j]=str[j-1];

str[j]=ch[0];

printf("\n%s",str);

break;

}

}

}

}

printf("\ninsert(if exit,enter 0):");

scanf("%s",ch);

}

}


生是编程人!!!!死是编程鬼!!!!颠峰人生!!!焚尽编程!!! 爱已严重死机!情必须重新启动!情人已和服务器断开连接!网恋也需要重新拨号!-----激情依旧
2005-04-09 22:57
激情依旧
Rank: 1
等 级:新手上路
威 望:2
帖 子:524
专家分:0
注 册:2005-4-4
收藏
得分:0 
//这个是本人和guitarliukai 一起写的链表 。请大家都多指教 程序的健壮性不如数组那位朋友写的好。

#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;

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");

Deletechar(head);

insert(head);

}


生是编程人!!!!死是编程鬼!!!!颠峰人生!!!焚尽编程!!! 爱已严重死机!情必须重新启动!情人已和服务器断开连接!网恋也需要重新拨号!-----激情依旧
2005-04-09 23:00
神vLinux飘飘
Rank: 13Rank: 13Rank: 13Rank: 13
来 自:浙江杭州
等 级:贵宾
威 望:91
帖 子:6140
专家分:217
注 册:2004-7-17
收藏
得分:0 
数组不是链表 而且没有用上动态数组,在内存上会比链表吃点亏.

你们老师不是让你们用链表写吗?


淘宝杜琨
2005-04-09 23:21
快速回复:大家帮我看看 26个字母删除的操作,怎么只能删除一个呀``???
数据加载中...
 
   



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

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