freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

數(shù)據(jù)結(jié)構(gòu)的c語言算法(已改無錯字)

2023-07-18 06:58:43 本頁面
  

【正文】 queue(qu,39。c39。)。 printf(出隊一次:)。 dequeue(qu,amp。x)。 printf(%c\n,x)。 printf(d入隊\n)。 enqueue(qu,39。d39。)。 printf(e入隊\n)。 enqueue(qu,39。e39。)。 printf(出對一次:)。 dequeue(qu,amp。x)。 printf(%c\n,x)。 printf(f入隊\n)。 enqueue(qu,39。f39。)。 printf(g入隊\n)。 enqueue(qu,39。g39。)。 printf(出隊一次:)。 dequeue(qu,amp。x)。 printf(%c\n,x)。 printf(余下元素出列:)。 while(len0) { dequeue(qu,amp。x)。 printf(%c ,x)。 } printf(\n)。system(pause)。}/*假設(shè)稱正讀和反讀都相同的字符序列為“回文”,例如:‘a(chǎn)bba’和‘a(chǎn)bcba’是回文,‘a(chǎn)bcde’和‘a(chǎn)babab’則不是回文。試寫一個算法判別讀入的一個以‘@’為結(jié)束符的字符序列是否是回文.*/includeincludedefine MaxLen 100typedef struct node{ char data。 struct node *next。}ode。ode *create(char s[]){ int i=0。 ode *h,*p,*r。 while(s[i]!=39。\039。) { p=(ode *)malloc(sizeof(ode))。 pdata=s[i]。pnext=NULL。 if(i==0) { h=p。r=h。/*r始終指向最后一個結(jié)點*/ } else { rnext=p。r=p。 } i++。 } return h。}int judge(ode *h){ char st[MaxLen]。 int top=0。 ode *p=h。 while (p!=NULL) { st[top]=pdata。 top++。 p=pnext。 } p=h。 while(p!=NULL) { top。 if(pdata==st[top]) p=pnext。 else break。 } if(p==NULL) return 1。 else return 0。}void main(){ char str[MaxLen]。 ode *h。 printf(輸入一個字符序列:)。 scanf(%s,str)。 h=create(str)。 if(judge(h)==1) printf(39。%s39。是回文,str)。 else printf(39。%s39。不是回文,str)。 getch()。}第四章 串:includeincludedefine MaxLen 20typedef strcut{ char ch[MaxLen]。 int len。}strtype。void create(strtype *s,char str[])/*將普通字符串賦給串*/{ strcpy(sch,str)。 slen=strlen(str)。}int length(strtype *s)/*求串長度*/{ return slen。}void copy(strtype *s1,strtype *s2)/*串的復(fù)制*/{ int i。 for(i=0。is1len。i++) s2ch[i]=s1ch[i]。 s2len=s1len。 s2ch[s2len]=39。\039。/*添加字符串結(jié)束符*/}strtypr subs(strtype *s,int pos,int n)/*求子串*/{ int i。 strtype sub。 if(pos+n1length(s1))/*參數(shù)不正確*/ =0。 else { for(i=pos1。ipos+n1。i++) [ipos+1]=sch[i]。 =n。 []=39。\039。 } return sub。}}int concat(strtype *s,strtype *t)/*連接兩個串*/{ int i。 if(slen+tlenMaxLen) return 0。 for(i=0。itlen。i++) sch[i+slen]=tch[i]。 slen=slen+tlen。 sch[slen]=39。\039。 return 1。}int ins(strtype *s,strtype *t,int i)/*插入一個子串*/{ int j。 if(slen+tlenMaxLen) return 0。 for(j=slen1。j=i1。j)/*i之后的所有元素后移tlen個位置*/ sch[j+tlen]=sch[j]。 for(j=0。jtlen。j++) sch[j+i1]=tch[j]。 slen=slen+tlen。 sch[slen]=39。\039。 return 1。}int del(strtype *s,int pos,int n)/*刪除一個子串*/{ int i。 if(pos+nslen) for(i=pos+n1。islen。i++) sch[in]=sch[i]。 slen=slenn。 sch[slen]=39。\039。 return 1。}void disp(strtype *s)/*輸出串*/{ if(slen==0) printf(空串\n)。 else printf(%d\n,sch)。}includeincludestrtype replace(strtype *s1,int i,int j,strtype *s2){ strtype s。 int n,k。 if(i+j1=s1len) { for(n=0。ni1。n++)/*把s1的前i1個字符賦給s*/ [n]=s1ch[n]。 for(n=0。ns2ch[n])/*連接s2串*/ [i+n1]=s2ch[n]。 =i+s2len1。 for(n=,k=i+j1。ks1len。n++,k++) /*連接s1的位置i及之后的字符*/ [n]=s1ch[k]。 =n。 []=39。\039。 } else { [0]=39。\039。 =0。 } return (s)。}void main(){ strtype s,s1,s2,s3,s4,s5,s6。 create(amp。s, (xyz)+*)。 printf(s=)。 disp(amp。s)。 s1=subs(amp。s,7,1)。/*s1=**/ s2=subs(amp。s,3,1)。/*s2=y*/ s3=subs(amp。s,6,1)。/*s3=+*/ s4=replace(amp。s,3,1,amp。s3)。 s5=replace(amp。s4,6,1,amp。s1)。 s6=replace(amp。s5,7,1,amp。s2)。 printf(t=)。 disp(amp。s6)。}includeincludeint index(strtype *s1,strtype *s2){ int i=0,j,k。 while (is1len) { j=0。 if(s1ch[i]==s2ch[j]) { k=i+1。j++。 while(ks1len amp。amp。 js2len amp。amp。 s1ch[k]==s2ch[j]) { k++。j++。 } if(j==s2len)/*s2中止時找到了子串*/ break。 else i++。 } else i++。 } if(is1len) return 1。 else return (i+1)。}void delall(strtype *s1,strtype *s2){ int n。 n=index(s1,s2)。 while(n=0) { del(s1,n,length(s2))。 n=index(s1,s2)。 } diap(s1)。}void main(){ strtype s1,s2。 char str[MaxLen]。 printf(字符串: )。 gets(str)。 create(amp。s1,str)。 printf(子串: )。 gets(str)。 create(amp。s2,str)。 delall(amp。s1,amp。s2)。}第五章 數(shù)組與廣義表:includeincludeincludedefine MaxLen 100typedef struct node/*定義廣義表結(jié)構(gòu)*/{ int tag。/*只取0(原子節(jié)點)或1(表節(jié)點)*/ struct node *link。/*后繼節(jié)點*/ union { char data。 struct node *slist。/*子表*/ }val。}gnode。void disastr(char s[],char hstr[])/*本函數(shù)為輔助建立廣義表的函數(shù)從字符串s中取出第一個39。,39。之前的子串賦給hstr,并使s成為刪除子串hstr和39。,39。之后的剩余串。若串s中沒有字符39。,39。,則操作后的hstr為操作前的s,而操作后的s為空串*/{ int i=0,j=0,k=0,r=0。 char rstr[MaxLen]。 while(s[i]amp。amp。(s[i]!=39。,39。||k)) { if(s[i]==39。(39。) k++。 else if(s[i]==39。)39。) k。 if(s[i]!=39。,39。||s[i]==39。,39。amp。amp。k) { hstr[j]=s[i]。 i++。j++。 } } hstr[j]=39。\039。 if(s[i]==39。,39。) i++。 while(s[i]) { rstr[r]=s[i]。 r++。i++。 } rstr[r]=39。\039。 strcpy(s,rstr)。}gnode *create(char s[])/*從字符串表示創(chuàng)建廣義表*/{ gnode *p,*q,*r,*gh。 char subs[MaxLen],hstr[MaxLen]。 int len。 len=strlen(s)。 if(!strcmp(s,()))/*空表的情況*/ gh=NULL。 else if(len==1)/*原子的情況*/ { gh=(gnode *)malloc(sizeof(gnode))。/*建立一個新節(jié)點*/ ghtag=0。/*構(gòu)造原子節(jié)點*/ gh=*s。 ghlink=NULL。 } else/*子表的情況*/ { gh=(gnode *)malloc(sizeof(gnode))。/*建立一個新節(jié)點*/ ghtag=1。 p=gh。 s++。/*除掉前面的一個39。(39。*/ strncpy(subs,s,len2)。 subs[len2]=39。\039。 do { disastr(subs,hstr)。/*將subs分為表頭和表尾*/ r=create(hstr)。 p=r。 q=p。 len=strlen(subs)。 if(len0) { p=(gnode *)malloc(sizeof(gnode))。 ptag=1。 qlink=p。 } }while(len0)。 qlink=NULL。 } return(gh)。}void disp(gnode *h)/*以字符串方式輸出廣義表*/{ gnode *p,*q。 printf(()。 if(h) do { p=h。 q=hlink。 while(qamp。amp。pamp。amp。!ptag)/*為原子且有后繼節(jié)點的情況*/ { printf(%d ,p)。 p=q
點擊復(fù)制文檔內(nèi)容
環(huán)評公示相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖片鄂ICP備17016276號-1