资源预览内容
第1页 / 共4页
第2页 / 共4页
第3页 / 共4页
第4页 / 共4页
亲,该文档总共4页全部预览完了,如果喜欢就下载吧!
资源描述
统计输入的一行字符串中各个字符出现的次数。算法:先输入一个字符串,对串中每一个字符,先到链表上逐个结点查找。若找到,给该字符频数加 1:否则为该字符产生一个结点,并插入链首。#include stdio.hstruct nodechar c;int count;struct node *next;#define ND struct node#define NP struct node*void print(NP h)while(_)printf(%c,%dn,h-c,h-count);h=h-next;NP search(NP h,char ch)NP p; p=h;while(p!=NULL)if(p-c=ch)p-count+; break; else p=p-next;if(p=NULL)p=_;p-c=ch; p-count=1;p-next=h;h=p;return h;main()char s300,*p=s; NP h;gets(s); h=NULL;while(*p!=0)h=search(h,*p); _; print(h);
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号