文档介绍:串串的动态存储方式采用链式存储结构和堆存储结构两种形式//串的动态存储结构——块链存储类型定义#defineCHUNKSIZE<用户定义的结点大小>;typedefstructchunk----------结点结构{charch[CHUNKSIZE];structchunk*next;}chunk typedefstruct {chunk*head,*tail;---------尾指针指示链表中的最后一个结点intlength;--------串的长度}//串的动态存储结构——堆结构charstore[maxsize]; typedefstructstring{ intlength,*stadr;/*length域指示串序列的长度stadr域指示串序列的store中的起始地址*/};//串基本操作的实现——串的模式匹配(求子串位置)intIndex_bf(strtps,t);{/*Brute-Force算法思想求模式串t在主串s中的定位函数*/i=1;j=1;/*指针初始化*/while((i<=)&&(j<=)){if([i]==[j]){i+1;j=j+1;}/*继续比较后继字符*/else{i=i-j+2;j=1;};/*指针后退重新开始匹配*/if(j>)returni-;elsereturn0;};/*Index_bf*///串的简单应用——统计字母出现频率letter_Frequency(strtptext){/*统计给定文本text中每个字母出现的频率*/charalph[]='abcdefghijklmnopqrstuvwxyz';intfreq[26];total=0;n=len(text);for(i=0;i<26;i++)freq[i]=0;/*freq为数组*/for(i=0;i<n;i++){ch=SubStr(text,i,1);j=Index(alph,ch);if(j>0){freq[j]=freq[j]+1;total=total+1;};}for(i=0;i<26;i++){freq[i]=freq[i]/total;printf(‘%f’,freq[i]);}};/*Letter_Frequency*/数组//稀疏矩阵的三元组表示法:#defineMAX10typedefstruct{inti,j;elemtypev;}node;typedefstruct{intmu,nu,tu;nodedata[MAX];}mat;//稀疏矩阵的转置运算的实现mat*zzjz(mat*a){;mat*b;/*转置后的矩阵b*/b=(mat*)malloc(sizeof(mat));=;=;=;/*a,b矩阵行、列交换*/bn=0;for(col=1;col<=;col++)/*按a的列序转置*/for(am=1;am<=;am++)/*扫描整个三元组表*/if([am].j==col)/*列号为col是转置*/{[bn].i=[am].j;[bn].j=[am].i;[bn].v=[am].v;bn++;/**/}returnb;/*返回转置矩阵的指针*/}//十字链表的结点类型定义如下:typedefstructnode{inti,j,v;structnode*down,*right;}szjd;//十字链表的建立表示法szlbcreate(szjd*m[],szjd*n[],int*hs,int*ls){intx,y,z,ms,ns;intk=0;szjd*p,*q,*s;ms=ns=0;scanf(“%d,%d”,&ms,&ns);for(k=0;k<ms;i++)m[k]=NULL;for(;k<ns;)n[k]=NULL;*hs=ms;*ls=ns;for(;;){scanf(%d,%d,%d”,&x,&y,&z);if(x==0||y==0)break;if((x>ms)||(y>ns))continue;s=(szjd*)malloc(sizeof(szjd));s->i=x;s->j=y;s->v=z;s->right=s->down=NULL;q=NULL;p=m[x-1];while((p!=NULL)&&(y>p->j)){q=p;p=p->right;}if(p==NULL){if(q==NULL)m[x-1]=s;elseq->right=s;}elseif(y==p->j){p->v=z;free(s