数据结构习题答案(严蔚敏)

数据结构习题答案(严蔚敏)

ID:83481023

大小:11.52 MB

页数:112页

时间:2023-06-28

上传者:灯火阑珊2019
数据结构习题答案(严蔚敏)_第1页
数据结构习题答案(严蔚敏)_第2页
数据结构习题答案(严蔚敏)_第3页
数据结构习题答案(严蔚敏)_第4页
数据结构习题答案(严蔚敏)_第5页
数据结构习题答案(严蔚敏)_第6页
数据结构习题答案(严蔚敏)_第7页
数据结构习题答案(严蔚敏)_第8页
数据结构习题答案(严蔚敏)_第9页
数据结构习题答案(严蔚敏)_第10页
资源描述:

《数据结构习题答案(严蔚敏)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

11.1ᑡᦪᦪᐗஹᦪஹᦪ᪀ஹ᪀ஹᦪᦪ஺ᦪᱥḄ⊤"஺ᙠ$%&'()ᢣᡠᨵ-.ᐭᑮ$%&)12$%&34ᜐᳮḄḄ78஺ᦪᐗᦪḄ9:ᓫ<ᙠ$%&34)=>?@AB᦮DEFὃ⇋ᜐᳮ஺ᦪឋJKLḄᦪᐗḄMᔠᦪḄABOM஺ᦪ᪀KPQRᙠASᡈUSᱯWᐵYḄᦪᐗḄMᔠ஺᪀ᦪ᪀ᙠ$%&)Ḅ⊤"஺ᦪABZḄMᔠW[ᙠ\BZM]ḄA^_?Ḅ78஺ᦪᢣABᦪ(`abW[ᙠc`]ḄA^_?஺AdᦪḄ᡽f஺1.2ghᦪ᪀ᦪḄᭆjk34l$m)ᦪᭆjḄno஺ᦪᒹqAdᦪḄᭆjrq[sAdᦪtuஹt஺AdᦪᵫᐹDmYxᑁzW[{|}~3ὅW[ᵨᡝᦪ8@⚜W[ᦪ஺ᦪ=>ᵫ3ὅW[ᒹW[ᡠᵨḄᦪᙠ\ᦪ]ᡠEFḄ_?஺ᙠW[ᦪ)Ḅᦪzᑖ_?zᑖ⌕W[ᑮᦪḄ᪀_?ὃ⇋ᦪḄ᪀_?ḄᐹD\᪵tt-@ᐸᵨᡝ}~Ḅᵨ|஺1.3lᨵᦪ᪀(D,R),ᐸ)D={dl,d2,d3,d4},R={r},r={(dl,d2),஺2/3),(43/4)}gᢥ¤¥)¤Ḅ¦§¨©¦ªᐸ᪀¤஺1.4g«᯿ᐗ^Ḅᦪᑖoᑏªᦪ¯ᦪᨵᳮᦪḄW[(ᨵᳮᦪᐸᑖOஹᑖ°ᙳ@²ᯠᦪ´ᑖ°@µḄᑖᦪ)஺ADTComplex{ᦪD={r,i|r,i@ᦪ}ᦪᐵYR={ீr,i>}9:_?InitComplex(&,C,re,im)_?Ï᪀⌼AB¯ᦪ3ᐸzÒzᑖo@reimDestroyCmoplex(&C)

1_?Ï├Ö¯ᦪcGet(C,k,&e)_?ÏᵨeÚÛ¯ᦪCḄÜkᐗḄZPut(&C,k,e)_?Ïᦋà¯ᦪCḄÜkᐗḄZ@eIsAscending(C)_?Ï᝞ϯᦪCḄäBᐗᢥᓣ4᣸ᑡᑣÚÛ1,ᔲᑣÚÛ0IsDescending(C)_?Ï᝞ϯᦪCḄäBᐗᢥë4᣸ᑡᑣÚÛ1,ᔲᑣÚÛ0Max(C,&e)_?ÏᵨeÚÛ¯ᦪCḄäBᐗ)ZîᜧḄABMin(C,&e)_?ÏᵨeÚÛ¯ᦪCḄäBᐗ)ZîðḄAB}ADTComplexADTRationalNumber{ᦪD={s,m|s,m@²ᯠᦪ´m@0}ᦪᐵYR={}9:_?InitRationalNumber(6,R,s,m)_?Ï᪀⌼ABᨵᳮᦪR,ᐸᑖOᑖ°ᑖo@smDestroyRationalNumber(&R)_?Ï├ÖᨵᳮᦪRGet(R,k,&e)_?ÏᵨeÚÛᨵᳮᦪRḄÜkᐗḄZPut(&R,k,e)_?ÏᦋàᨵᳮᦪRḄÜkᐗḄZ@eIsAscending(R)_?ÏõᨵᳮᦪRḄäBᐗᢥᓣ4᣸ᑡᑣÚÛ1,ᔲᑣÚÛ0IsDescending(R)_?ÏõᨵᳮᦪRḄäBᐗᢥë4᣸ᑡᑣÚÛ1,ᔲᑣÚÛ0Max(R,&e)_?ÏᵨeÚÛᨵᳮᦪRḄäBᐗ)ZîᜧḄABMin(R,&e)_?ÏᵨeÚÛᨵᳮᦪRḄäBᐗ)ZîðḄAB}ADTRationalNumber1.6ᙠ34l$)>ᵨᑡSLḄª┯ᜐᳮøù(1)ᵨexitúûü᡻F1þÿ┯(2)ᦪḄᡈ┯(3)᦮Ḅᦪᦪᡈ┯஺

2!"#$%&ᔜ(Ḅ)*+஺,-(l)exit3ᵨ563┯ᜐᳮ9:;<=>?@AḄ᡻=9CDEF஺(2)ᦪḄᑨ?Hᔲ3ᵨ5J@AḄK9L5MN@AḄOPQJ(3)ᵨ᦮ᦪS=┯ᜐᳮḄ)+T;UV┯W9L5XYZ┯஺L7ᙠ@A^>9;_ᵨ`ᑡ$%&MNbVcbᐭ-(1)fgscanfcprintfop(2)fgᦪḄᦪqrs⌴(3)fgᐰO◚rs⌴஺!"#$%&Ḅ)*+஺,-(1)ᵨscanfcprintfwxS=bᐭbVḄyᜐTz{ஹw}9~*+T◤⌕ᐸS=rᑴ9ᳲ9᝞VN┯9ᑣ᦮EFḄ஺(2)fgᦪḄᦪs⌴S=bᐭbV9L5MNḄ◚9V┯Ḅ;஺(3)fgᐰOḄ◚rs⌴S=bᐭbVᨬ%L9◤ᦋḄᓽ;9~gḄᐰO@AḄ¡¢஺1.8,-পn-1(2)n-1(3)n-1(4)n+(nT)+(n-2)+...+1=”(5)1+(1+2)+(1+2+3)+...+(1+2+3+...+n)=^^—,=i2°"+1)=ᢳ2+j)=$2+*=n(n+l)(2n+1)+—n(n+1)=\஻(”+1)(2¸+3)(6)n(7)[JRᔣ`½᦮(8)11001.9,-o(logn)2count=logn-22L11ÃÄᨵMNÆÇḄÈÉ&9ᐸÊËÌᩖÎᑖO(2")c0(/Ò)9ᎷNM^ÉÔ;ÕÖ×ÉḄÊË1O7Ø(100ᜩ),ÚÛØ;᡻=ÜÝCD(᪷

3ß#àCDᩭâÉÉ&ÊËÌᩖÎ)1()5ã஺äᙠåᩩç`9#ÈÉ&;,ä⚪Ḅéê(ᓽnḄì)ᔜíîÉ&ï〉ñíòóôᳮᵫ஺,-2"=1(/2=40nnw=1012n=16ᑣ5Æ᪵Ḅ÷øãᦪn,ᙠ#éê`9ùúÉ&ᡠüýḄþÿ⌕ᜧ஺ᦑᙠ〉஺1.12পফ┯ব┯(4)ম┯1.13$%&'(n*+,-.ᦪ஻2250nlog2஻Ḅ9:;<=>&nᙠ?@Bᑁ.ᦪḄ*ᜧD50஻log?"Ḅ*஺Ḅ9:;438Jiv>50/7logn21.14পg(n)Gফg(n)Gবf(n)G(4)f(n)G1.16$ᑏTᜧUIVWXYZ[\ᐭḄ^᦮ᦪX,Y2ZḄ*intmax3(intx,inty,intz)(if(x>y)if(x>z)returnx;elsereturnz;elseif(y>z)returny;elsereturnz;)1.17pqk▤ᦾuv᜿[ᑡḄ&yz/o=஺/|=0,....f_-0>f_-1}k2kxfn=fn-l+fn-2+…n=k,k+l,…$~ᑏk▤ᦾuv᜿[ᑡḄm⚗*Ḅ.ᦪk2mᙳ*ᵨḄᙠ.ᦪᦪ⊤Y஺k>0z▤ᦪnzᦪᑡḄn⚗intFibonacci(intk,intn){if(k

4p=newint[k+1];if(!p)exit(OVERFLOW);inti,j;for(i=0;i

5temp.TotalSum=temp.MaleSum+temp.FemaleSum;returntemp;)1.19$~ᑏ®i!*2,Ḅ*=ᐭᦪËa[O..arrsize-l]ḄᑖÏ(i=l,2,…,n)஺Ꮇ%®¯ᐕÒḄ᦮ᦪᨬᜧ*zmaxint,ᑣLn>arrsizeᡈÖ×஺2Ø>maxintJÙᢥY┯ᜐᳮ஺ÛÜ⌱Þßàz,áḄY┯ᜐᳮâ஺#include#includeSdefineMAXINT65535ttdefineArrSize100intfun(inti);intmain()(inti,k;inta[ArrSize];cout«z/Enterk:஻cin>>k;if(k>ArrSize~l)exit(0);for(i=0;i<=k;i++){if(i==0)a[i]=l;else{if(2*i*a[i-l]>MAXINT)exit(0);elsea[i]=2*i*a[i-l];))for(i=0;i<=k;i++){if(a[i]>MAXINT)exit(O);elsecout«a[i]«z஻}return0;}1.20$~ᑏᐗ⚗Ḅ*í“(x)=£aRḄ*e,(x0),=>&²/=0ðñḄ᡻¤Wᦪ2᦮ḄJóôᩖö஺ÛÜ⌱Þßàz,áḄXᐭ2XYâ஺÷⚪ḄXᐭzᜐ஽=0,1,…2஻XYzú(%0)஺

6#include#include^defineN10doublepolynomail(inta[],inti,doublex,intn);intmain(){doublex;intn,i;inta[N];cout<<”XᐭþÏḄ*x:;cin>>x;cout<<”Xᐭ⚗Ḅ▤Wn:";cin>>n;if(n>N-l)exit(0);cout<<"Xᐭ⚗Ḅÿᦪa[0]—a[n]:";for(i=0;i<=n;i++)cin>>a[i];cout«/?Thepolynomailvalueis$$«polynomail(a,n,x,n)<0)returna[n-i]+polynomail(a,i-1,x,n)*x;elsereturna[n];),-.Ḅ012ᩖ45஺(n)஺2ឋ⊤2.19:;<=>ᭆ@ḄABCᜮᢣ┐$ᜮGH$✌ᐗGH(KL>ᐗMGH)஺NCᜮᢣ┐OᢣᔣQ⊤SKL>GHḄᢣ┐஺✌ᐗGHOᢣQ⊤STUKL>ᦪVᐗMḄGH஺ᜮGHOᙠ✌ᐗGHXY▬[ḄL>GH$\GH]TUᦪVᐗM$ᐸᢣ┐_ᢣᔣ✌ᐗGH$ᐸ`ᵨb⌕O5defgQ⊤Ḅh`஺ij;gk⊤ஹmk⊤;n✌ᐗGHḄh`opqLᜐᳮ஺2.2tk⚪஺NC(1)ᙠvw⊤Sxᐭᡈᑤ◀L>ᐗM$◤⌕~ᙳ⊤SLᐗM,ᐹḄᐗᦪᐗᙠ⊤Ḅᨵᐵ஺(2)vw⊤SḄᐗMḄᱥᳮ஺ᓫQ⊤SḄᐗMḄᱥᳮRL஺(3)ᙠᓫQ⊤S$◀d✌ᐗGH᜜$LGHḄTUᵫᐸHḄḄᢣ"஺(4)#ᙠ$Ḩ⊤&ᜮ()ஹ+,ᵨ./ᐭ1ᑤ◀✌ᐗ()56ᵨ78ᱯ:ᜐᳮ஺2.3ᙠ<ᵨvw⊤Q⊤¡NC¢£ឋ⊤ḄᦪVᐗMᙠᱥᳮO¥¦TUḄ0᎛$ᵨvw⊤ᵨQ

7⊤$ᐸᱯHOj;op©ªT«஺2.4g;<ᓫQ⊤ᑖB᡻p<ᑡᔜ°w±$²³´Gµ¶·¸஺L-<\2\\------Oil------*7||——Oil——>|8[HS解••U8—►Lফ8TS8-S5-►…S16—►-S16-VS2.5³´᡻p<ᑡᔜp¼½¾ᔜᢣ┐nQ⊤Ḅ¶·¸஺NCLߟ►1PL-►15——>7AL7p

8mi—mi—L—►ߟ>2——►4——►61——*8¿ÀP2.6N:a.(4)(1)b.(7)(11)(8)(4)(1)c.(5)(12)d.(9)(1)(6)2.7NCa.(11)(3)(14)b.(10)(12)(8)(3)(14)c.(10)(12)(7)(3)(14)d.(12)(11)(3)(14)e.(9)(11)(3)(14)2.8NCa.(7)(3)(6)(12)b.(8)(4)(5)(13)c.(15)(1)(11)(18)d.(16)(2)(10)(18)e.(14)(9)(17)2.9Æ:;<-.ḄÇÈ஺(NC(1)᝞µLḄË4]ÌÍ2,ÎLḄ✌ᐗGHÏᡂÑᐗGH஺(2)ÎᓫÒÓQ⊤ÔᡂÕ>ᓫÒÓQ⊤஺2.10ᢣ´;<-.SḄ┯×ØÙᦔXᜐ$²Îiᦋᑏ5L>ÝÞßàáᦔḄ-.஺StatusDeleteK(SqList&a,inti,intk){஻,ê°ëvwTUG᪀Ḅ£ឋ⊤aSᑤ◀Ki>ᐗMíḄk>ᐗMif(ia.length)returnINFEASIBLE;//÷ᦪ]ᔠ.else{for(count=l;countᐗMfor(j=a.length;j>=i+l;jL)a.elem[j-i]=a.elem[j];a.length—;returnOK;NCStatusDeleteK(SqList&a,inti,intk)

9஻ëvwTUG᪀Ḅ£ឋ⊤aSᑤ◀Ki>ᐗMíḄk>ᐗM஻ú·iḄûüë஺ýþintj;if(i<0I|i>a.length-1|k<01|k>a.length-i)returnINFEASIBLE;for(j=0;j<=k;j++)a.elem[j+i]=a.elem[j+i+k];a.length=a.length-k;returnOK;)2.11[vw⊤vaSḄᦪVᐗM⌴ᨵ஺ᑏxᐭᑮ⊤Ḅ〉ᢝ⊤Ḅᨵឋ஺StatusInsertOrderList(SqList&va,ElemTypex)(஻ᙠ⌴!Ḅ⊤va"ᐭᐗ$x%&ᐸ(ᡂ*⊤Ḅinti;if(va.length=va9listsize)return(OVERFLOW);for(i=va.length;i>0,x⊤஺?A=6'=@⊤ᑣA=8G?4=@⊤B8T@⊤ᡈὅEὅᙳF*@⊤G4Ḅ✌ᐗIJB'Ḅ✌ᐗᑣA<8GᔲᑣA>3஺ᑏLMNA,8ᜧIḄ஺StatusCompareOrderList(SqList&A,SqList&B)(inti,k,jGk=A.length>B.length?A.length:B.length;for(i=0;iB.elem[i])j=l;if(A.elem[i]k)j=l;if(B.length>k)j=-l;if(A.length==B.length)j=0;returnj;2.13ᑏᙠOᜮQRḄᓫT⊤Q᪀VWXឋ⊤YZLocate(L,x);

10intLocateElem_L(LinkList&L,ElemTypex)(inti=0;LinkListp=L;while(p&&p->data!=x){p=p->next;i++|)if(!p)return0;elsereturni;)2.14ᑏᙠOᜮQRḄᓫT⊤Q᪀VWXឋ⊤YZLength(L)஺஻ᓫT⊤ḄintListLength_L(LinkList&L){inti=0;LinkListp=L;if(p)p=p-next;while(p){p=p->next;i++|}returni;)2.15ᢣ┐ha,hbᑖ4ᢣᔣELᓫT⊤ḄᜮQR%GELT⊤Ḅᑖ4*m,n஺ᑏELT⊤ᙠᎷ+ᢣ┐heᢣᔣ=ḄT⊤ḄᜮQR%⌕Ḅᡂ஺ᑖ᪆¢ḄḄ£ᩖ஺voidMergeList_L(LinkList&ha,LinkList&hb,LinkList&hc)(LinkListpa,pb;pa=ha;pb=hb;while(pa->next&&pb->next){pa=pa->next;pb=pb->next;}if(!pa->next){hc=hb;while(pb->next)pb=pb->next;pb->next=ha->next;

11else{hc=ha;while(pa->next)pa=pa->next;pa->next=hb->next;))2.16ᢣ┐la,lbᑖ4ᢣᔣEL§ᜮQRᓫT⊤"Ḅ✌ᐗQR஺¨ᑡª«⊤la"ᑤ◀®iLᐗ$ᐳlenLᐗ$=¯°ᐭᑮ⊤1b"®iLᐗ$±;஺²³ªᔲ´µ¶?ᨵ┯ᦋ´±஺StatusDeleteAndlnsertSub(LinkedListla,LinkedListlb,inti,intj,intlen)(if(i<0||j<0||ler)<0)returnINFEASIBLE;p=la;k=l;while(knext;k++;}q=P|while(k<=len){q=q->next;k++;}s=lb;k=l;while(knext;k++;}s->next=p;q->next=s->next;returnOK;ijStatusDeleteAndlnsertSub(LinkList&la,LinkList&lb,inti,intj,intlen){LinkListp,q,s,prev=NULL;intk=l;if(i<0||j<0||len<0)returnINFEASIBLE;//ᙠla⊤"ÉÊ®iLQRP=la;while(p&&knext;k++;)if(!p)returnINFEASIBLE;//ᙠla⊤"ÉÊ®i+len-1LQRq=P|k=l|while(q&&knext;k++;

12if(!q)returnINFEASIBLE;//ᡂᑤ◀ËÌi=lḄÍÎ◤⌕ᱯÑᜐᳮif(!prev)la=q->next;elseprev->next=q->next;//«la"ᑤ◀ḄQRᐭᑮlb"if(j=l){q->next=lb;lb=p;}else{s=lb;k=l;while(s&&knext;k++;)if(!s)returnINFEASIBLE;q->next=s->next;s->nextÔp;஻ᡂᐭ}returnOK;}2.19Xឋ⊤"Ḅᐗ$Ö⌴ᨵ᣸ᑡ%ᓫT⊤ZØÙQ᪀஺ᑏÚᦔḄᑤ◀⊤"ᡠᨵÖᜧJminkGIJmaxkḄᐗ$(?⊤"Øᙠ᪵Ḅᐗ$):ÞßàᑤQR@%ᑖ᪆¢ḄḄ£ᩖ(ËÌmink,maxkªáâḄELãä寰ḄÖ,⊤"Ḅᐗ$æ:/F:)஺StatusListDeleteL(LinkList&L,ElemTypemink,ElemTypemaxk){LinkListp,q,prev=NULL;if(mink>maxk)returnERROR;P=L;prev=p;p=p->next;while(p&&p->datadata<=mink){prev=p;p=p->next;)else{prev->next=p->next;q=P|p=p->next;free(q);

13returnOK;)2.20:2.19⚪ᩩêᑏÚᦔḄᑤ◀⊤"ᡠᨵÖæ:Ḅëìᐗ$(&íYZ=ḄXឋ⊤"ᡠᨵᐗ$ḄÖᙳFæ:):ÞßàᑤQR@%ᑖ᪆¢ḄḄ£ᩖ஺voidListDelete_LSameNode(LinkList&L)(LinkListp,q,prev;P=L;prev=p;p=p->next;while(p){prev=p;p=p->next;if(p&&p->data==prev->data){prev->next=p->next;q=P|p=p->next;free(q);)))2.21ᑏVW⊤Ḅîᙢ⌮ᓽᑭᵨô⊤ḄØÙ@Xឋ⊤(4,…⌮*…)஺஻⊤Ḅ⌮StatusListOppose_Sq(SqList&L)(inti;ElemTypex;for(i=0;i

14LinkListp,q;P=L;p=p->next;L->next=NULL;while(p){q=P|p=p->next;q->next=L->next;L->next=q;returnOK;2.23+Xឋ⊤A=…3=ù4/,/஻úᑏLᢥ¨ᑡüᑣᔠ%A,B*Xឋ⊤CḄᓽ&íC=(a,b,---,a,b,b,---,b)-W";[lmmm+lnC=(%,…,ு஻஺ឋ⊤A,BCᙳᓫ⊤᪀C⊤ᑭᵨA⊤B⊤!Ḅ#$%᪀ᡂ஺'()ᓫ⊤Ḅ*+,mnᙳ/01஺2)஻3ᔠ56Ḅ78ᙠC⊤!5ᑤ◀B⊤StatusListMerge_LHLinkList&A,LinkList&B,LinkList&CKLinkListpa,pb,qa,qb;pa=A->next;pb=B->next;C=A;while(pa&&pb){qa=pa;qb=pb;pa=pa->next;pb=pb->next;qb->next=qa->next;qa->next=qb;)if(!pa)qb->next=pb;pb=B;free(pb);returnOK;2.24Ꮇaᨵcdᢥᐗg,⌴iᨵj᣸ᑡḄឋ⊤AB,ᙳᓫ⊤᪀mnᑏpq3A⊤B⊤r5ᡂsdᢥᐗg,⌴tᨵjHᓽv⌴iᨵjᐕx⊤!yᨵ,z{ḄᐗgK᣸ᑡḄឋ⊤C,5⌕}ᑭᵨ~⊤HᓽA⊤B⊤K

15Ḅ#$%᪀⌼C⊤஺2)஻3ᔠ5⌮6Ḅ78ᙠC⊤!5ᑤ◀B⊤StatusListMergeOppose_L(LinkList&A,LinkList&B,LinkList&C)(LinkListpa,pb,qa,qb;pa=A;pb=B;qapa;஻paḄᢣ┐qb=pb;//pbḄᢣ┐pa=pa->next;pb=pb->next;A->next=NULL;C=A;while(pa&&pb){if(pa->datadata){qa=pa;pa=pa->next;qa->next=A->next;஻3ᨬ#ᐭA⊤⊤ᜮA->next=qa;)else{qb=pb;pb=pb->next;qb->next=A->next;஻3ᨬ#ᐭA⊤⊤ᜮA->next=qb;))while(pa){qa=pa;pa=pa->next;qa->next=A->next;A->next=qa;)while(pb){qb=pb;pb=pb->next;qb->next=A->next;A->next=qb;}pb=B;free(pb);returnOK;}

162.25Ꮇacdᐗg,⌴iᨵj᣸ᑡḄឋ⊤ABᑖ⊤cdᔠ(ᓽ{s⊤!Ḅᐗg,ᔜz{)⌕}$%᪀ᡂsdឋ⊤C,ᐸᐗgAB!ᐗgḄ¡⊤C!Ḅᐗgᨵ,⌴iᨵj᣸ᑡ஺¢£¤j⊤nᑏ}CḄpq஺2)//3AஹB}¡6Ḅ78ᙠC⊤!StatusListCrossSq(SqList&A,SqList&B,SqList&C)inti=0,j=0,k=0;while(iB.elem[j])j++;else{ListInsert_Sq(C,k,A.elem[i]);i++¬k++;returnOK;)2.26⌕}{2.25⚪஺¢£ᓫ⊤nᑏ}CḄpq஺2)//3AஹB}¡6Ḅ78ᙠC⊤!5ᑤ◀B⊤StatusListCross_L(LinkList&A,LinkList&B,LinkList&C)LinkListpa,pb,qa,qb,pt;pa=A;pbB;qa=pa;//paḄᢣ┐qbpb;஻pbḄᢣ┐pa=pa->next;pb=pb->next;C=A;while(pa&&pb){if(pa->datadata){ptpa;pa=pa->next;qa->next=pa;free(pt);elseif(pa->data>pb->data){pt=pb;

17pb=pb->next;qb->next=pb;free(pt);)else{qa=pa;pa=pa->next;}}while(pa){pt=pa;pa=pa->next;qa->next=pa;free(pt);)while(pb){pt=pb;pb=pb->next;qb->next=pb;free(pt);)pb=B;free(pb);returnOK;)2.27£2.25⚪Ḅᩩ±²c#³ᦋ£¤j⊤µ¶nᑏ}·⊤CḄpq஺(1)Ꮇaᙠ{s⊤(AᡈB)!º»ᙠ,z{Ḅᐗg¼⌕}¶½ᡂḄ⊤C!Ḅᐗg,ᔜz{¬(2)ᑭᵨA⊤$%8⊤C஺2)(1)//AஹB}¡ᯠ6ᑤ◀z{ᐗg378ᙠC⊤!StatusListCrossDelSame_Sq(SqList&A,SqList&B,SqList&C){inti=0,j=0,k=0;while(iB.elem[j])j++;else{if(C.length==0){ListInsert_Sq(C,k,A.elem[i]);k++;

18elseif(C.elem[C.length-1]!=A.elem[i]){ListInsert_Sq(C,k,A.elem[i]);k++;}i++¬)}returnOK;)(2)//AஹB}¡ᯠ6ᑤ◀z{ᐗg378ᙠA⊤!StatusListCrossDelSame_Sq(SqList&A,SqList&B){inti=0,j=0,k=0;while(iB.elem[j])j++;else{if(k==0){A.elem[k]=A.elem[i];k++;)elseif(A.elem[k]!=A.elem[i]){A.elem[k]=A.elem[i];k++;)i++¬)}A.length=k;returnOK;)2.28£2.25⚪Ḅᩩ±²c#³ᦋ£ᓫ⊤µ¶nᑏ}·⊤CḄpq஺(1)Ꮇaᙠ{s⊤(AᡈB)!º»ᙠ,z{Ḅᐗg¼⌕}¶½ᡂḄ⊤C!Ḅᐗg,ᔜz{¬(2)ᑭᵨ~⊤(A⊤ᡈB⊤)!Ḅ#᪀ᡂ⊤C,5Á8A⊤!ḄÂᵨ#$%஺2)(1)//AஹB}¡78ᙠC⊤!5ᑤ◀z{ᐗgStatusListCrossDe1Same_L(LinkList&A,LinkList&B,LinkList&C)

19LinkListpa,pb,qa,qb,pt;pa=A;pb=B;qa=pa;//paḄᢣ┐qb=pb;//pbḄᢣ┐pa=pa->next;pb=pb->next;C=A;while(pa&&pb){if(pa->datadata){pt=pa;pa=pa->next;qa->next=pa;free(pt);)elseif(pa->data>pb->data){pt=pb;pb=pb->next;qb->next=pb;free(pt);)else{if(pa->data==qa->data){ptpa;pa=pa->next;qa->next=pa;free(pt);)else{qa=pa;pa=pa->next;)})while(pa){pt=pa;pa=pa->next;qa->next=pa;free(pt);)while(pb){pt=pb;

20pb=pb->next;qb->next=pb;free(pt);)pb=B;free(pb);returnOK;)(2)//AஹB}¡78ᙠA⊤!5ᑤ◀z{ᐗgStatusListCrossDelSame_L(LinkList&A,LinkList&B){LinkListpa,pb,qa,qb,pt;pa=A;pb=B;qapa;஻paḄᢣ┐qbpb;஻pbḄᢣ┐pa=pa->next;pb=pb->next;while(pa&&pb){if(pa->datadata){pt=pa;pa=pa->next;qa->next=pa;free(pt);)elseif(pa->data>pb->data){pt=pb;pb=pb->next;qb->next=pb;free(pt);)else{if(pa->data==qa->data){pt=pa;pa=pa->next;qa->next=pa;free(pt);)else{qa=pa;pa=pa->next;

21while(pa){pt=pa;pa=pa->next;qa->next=pa;free(pt);}while(pb){pt=pb;pb=pb->next;qb->next=pb;free(pt);}pb=B;free(pb);returnOK;)2.29ÄÅA,BCÆd⌴iᨵjḄឋ⊤⌕}£A⊤᝞²È)ᑤÉÊËÌᙠB⊤!ÍÎᙠC⊤!ÍḄᐗg஺¢£¤j⊤nᑏÏÐÑÈḄpq5ᑖ᪆ÓḄpqḄ%Ôᩖ+('()⚪!Öᨵᱯᢣ{s⊤!Ḅᐗg,ᔜz{)஺2)஻ᙠA!ᑤ◀ÌᙠB!ÍÎᙠC!ÍḄᐗg78ᙠD!StatusListUnion_Sq(SqList&D,SqList&A,SqList&B,SqList&C){SqListTemp;InitList_Sq(Temp);ListCross_L(B,C,Temp);ListMinus_L(A,Temp,D);)2.30⌕}{2.29⚪஺¢£ᓫ⊤nᑏpqmÁ8A⊤!ḄÂᵨ#$%஺2)//ᙠA!ᑤ◀ÌᙠB!ÍÎᙠC!ÍḄᐗg5Á8BஹCStatusListUnion_L(LinkList&A,LinkList&B,LinkList&C){ListCross_L(B,C);ListMinus_L(A,B);)//}ᔠA-B,78ᙠA⊤!5ᑤ◀B⊤StatusListMinus_L(LinkList&A,LinkList&B)(LinkListpa,pb,qa,qb,pt;pa=A;

22pb=B;qapa;//paḄᢣ┐qb=pb;஻pbḄᢣ┐pa=pa->next;pb=pb->next;while(pa&&pb){if(pb->datadata){pt=pb;pb=pb->next;qb->next=pb;free(pt);}elseif(pb->data>pa->data){qa=pa;pa=pa->next;)else{pt=pa;pa=pa->next;qa->next=pa;free(pt);)}while(pb){pt=pb;pb=pb->next;qb->next=pb;free(pt);)pb=B;free(pb);returnOK;}2.31ᎷaÚdᓫᔣÜÝ⊤Ḅ*+ᜧß1,⊤!ÌÂᜮ#àÂᜮᢣ┐஺ÄÅsᢣᔣ⊤!Úd#Ḅᢣ┐,¢nᑏpqᙠ⊤!ᑤ◀ᢣ┐sᡠᢣ#Ḅ#஺2)//ᙠᓫÜÝ⊤s!ᑤ◀SḄ#StatusListDelete_CL(LinkList&S)LinkListp,q;if(S==S->next)returnERROR;q=S;

23p=S->next;while(p->next!=S){q=P¬p=p->next;)q->next=p->next;free(p);returnOK;)2.32ÄÅᨵsdᓫᔣÜÝ⊤ᐸåd#!yÆdæ)pre,datanext,ᐸ!dataᦪèænextᢣᔣ6é#Ḅᢣ┐æpreàᢣ┐æ¼êḄ,$¢nᑏpq3ëᓫᔣÜÝ⊤ᦋìᔣÜÝ⊤ᓽípreᡂᢣᔣ#Ḅᢣ┐æ஺2)//îïsd$ḄÜÝ⊤StatusInitList_DL(DuLinkList&L){L=(DuLinkList)malloc(sizeof(DuLNode));if(!L)exit(OVERFLOW);L->pre=NULL;L->next=L;returnOK;)//ᔣÜÝ⊤!ᐭsd#StatusListinsertDL(DuLinkList&L,ElemTypee)(DuLinkListp;p=(DuLinkList)malloc(sizeof(DuLNode));if(!p)returnERROR;p->data=e;p->next=L->next;L->next=p;returnOK;)//3ᓫÜÝ⊤ᦋᡂìᔣ⊤StatusListCirToDu(DuLinkList&L)(DuLinkListp,q;q=L;p=L->next;while(p!=L){p->pre=q;Q=P¬p=p->next;

24if(p==L)p->pre=q;returnOK;)2.33ÄÅᵫsdឋ⊤⊤Ḅឋ⊤!yᨵÆøùúḄᦪèᐗg(᝞)ùûùúஹᦪùùúᐸüùú)¢nᑏpq3ýឋ⊤ᑖᒘÆdÜÝ⊤ᐸ!ådÜÝ⊤⊤Ḅឋ⊤!ᙳÿ஺//ᓫ⊤Lᑜᑖᡂ3ᓫ⊤StatusListDivideInto3CL(LinkList&L,LinkList&sl,LinkList&s2,LinkList&s3){LinkListp,q,ptl,pt2,pt3;p=L->next;ptl=sl;pt2=s2;pt3=s3;while(p){if(p->data>=6O'&&p->data<=69'){q=p;p=p->next;q->next=ptl->next;ptl->next=q;ptl=ptl->next;)elseif((p->data>=6&&p->data<=6Z")||(p->data>=6a'&&p->data<=6z')){q=P=p=p->next;q->next=pt2->next;pt2->next=q;pt2=pt2->next;)else(q=p;p=p->next;q->next=pt3->next;pt3->next=q;pt3=pt3->next;)q=L;free(q);

25returnOK;)ᙠ2.34C2.36⚪F6“Hᡈᢣ┐Lᔣ⊤”FGXorLinkedListPᢣ┐HᡈQᦪXorPSTUtypedefstructXorNode{chardata;structXorNode*LRPtr;}XorNode,*XorPointer;typedestruct{஻]ᜮ_`ḄHᡈᢣ┐Lᔣ⊤XorPointerLeft,Right;஻ᑖcᢣᔣ⊤ḄdePfg}XorLinkedList;XorPointerXorP(XorPointerp,XorPointerq);//ᢣ┐HᡈQᦪXorPhiᢣ┐pPqḄHᡈj2.34ᎷlᙠmnopqrFsᐭᢣ┐Ḅuᐗwm“Hᡈ”6xaPbUᢣ┐6ᑣa@bḄwm_|}U~ᢣ┐6a®(a®b)=(a©a)©b=b(a®b)©b=a®(b®b)=aᑣᑭᵨᢣ┐ᩭLᔣ⊤L஺⊤LFḄ_`dataPLRPtr6ᐸFLRPtr_`Ḅdf_`ᢣ┐(ᙠUNULL)ḄHᡈ஺xlᢣ┐L.Leftᢣᔣ⊤FḄᨬd_`6LRightᢣᔣ⊤FḄᨬf_`6ᑣdᔣfᡈfᔣdᔊLᔣ⊤Ḅ஺ᑏmnᢥ¡ᔣ¢£¤¥⊤Fᔜᐗ§Ḅj஺StatusTraversingLinkList(XorLinkedList&.L,chard){XorPointerp,left,right;if(d==6I'lld=='L'){p=L.Left;left=NULL;while(p!=NULL){VisitingData(p->data);left=p;p=XorP(left,p->LRPtr);elseif(d==6r|id==6R'){p=L.Right;right=NULL;while(p!=NULL){VisitingData(p->data);right=p;p=XorP(p->LRPtr,right);

26elsereturnERROR;returnOK;)2.35®ᵨ2.34⚪ᡠpḄ°_᪀6ᑏ¥ᙠ²i_`³´µᐭ_`Ḅmn஺2.36®ᵨ2.34⚪ᡠpḄ°_᪀6ᑏ¥ᑤ◀²i_`Ḅmn஺2.37l¹ºᜮ_`ḄLᔣ⊤⊤»Ḅ¼ឋ⊤L=(q,¾)஺ᑏ¿ÀᩖÂ0(n)Ḅmn6Lᦋ⌼UL=(q,%,//Lᔣ⊤L=(al,a2,…,an)ᦋ⌼U(al,a3,...,an,...,a2)StatusListChange_DuL(DuLinkList&L){inti;DuLinkListp,q,r;p=L->next;r=L->pre;i=l=while(p!=r){if(i%2==0){q=p;p=p->next;//ᑤ◀_`q->pre->next=q->next;q->next->pre=q->pre;//µᐭᑮᜮ_`Ḅd☢q->pre=r->next->pre;r->next->pre=q;q->next=r->next;r->next=q;}elsep=p->next;i++=)returnOK;}2.38lᨵLᔣ⊤6_`F◀ᨵpre,dataPnextÎ᜜6ÐÑlÒÓÔ⚣Âfreq஺ᙠ⊤Ö×ᵨ³´6⚣ÂfreqḄjᙳÙÚᓄUI,ÜÝÞ⊤ßà£Located,x)Ḅá6ÖÓÔḄ_`(ᓽᐗ§jãäxḄ_`)FḄ⚣ÂfreqḄjåÑ1,çè᦮⊤F_`³¿Ḅ£ê6ëᐸᢥÓÔ⚣Âì⌴ÑḄ£êîê᣸ᑡ6¹åÚñòᢝÖ⚣ôÓÔḄ_`õö☠ø⊤ᜮ_`஺ùᑏᔠûp⌕ýḄLocateḄmn஺

27DuLinkListListLocate_DuL(DuLinkList&L,ElemTypee){DuLinkListp,q;p=L->next;while(p!=L&&p->data!=e)p=p->next;if(p==L)returnNULL;else{p->freq++;//ᑤ◀_`p->pre->next=p->next;p->next->pre=p->pre;//µᐭᑮᔠ〉Ḅq=L->next;while(q!=L&&q->freq>p->freq)q=q->next;if(q==L){p->next=q->next;q->next=p;p->pre=q->pre;q->pre=p;)else{஻ᙠqᐭp->next=q->pre->next;q->pre->next=p;p->pre=q->pre;q->pre=p;)returnp;})ᙠ2.39'2.40⚪+,-./⚗12ᵨḄ45678᪀SqPoly>?@typedefstruct{intcoef;intexp;}PolyTerm;typedefstruct{஻/⚗1Ḅ45678᪀PolyTerm*data;intlast;}SqPoly;2.39GH-./⚗1%(x)=jx஺+஺2/+…+c,H,,ᐸ+஻>…>620,q஺0(i=1,2,…,m),T21஺U2ᵨ67VW/⚗1⚗ᦪmᡂZ[Ḅ45678᪀,\ᑏ^ᓃ(%)Ḅ`a(/@b>c),dᑖ᪆gḄ

28`aḄhijᩖl஺mntypedefstruct{intcoef;intexp;}PolyTerm;typedefstruct{PolyTerm*data;intlast;}SqPoly;//opqr/⚗1StatusPolylnit(SqPoly&L)(inti;PolyTerm*p;cout<ீ஻uvᐭ/⚗1Ḅ⚗ᦪ:஻xcin>>L.last;L.data=(PolyTerm*)malloc(Llast*sizeof(PolyTerm));if(!Ldata)returnERROR;p=L.data;for(i=0;i>p->coef;cout<<஻uvᐭᢣᦪ:஻;cin>>p->exp;p++x)returnOK;)//^/⚗1ḄcdoublePolySum(SqPoly&L,doublexO){doublePn,x;inti,j;PolyTerm*p;p=L.data;for(i=0,Pn=0;iexp;j++)x=x*xO;Pn=Pn+p->coef*x;}returnPn;2.402ᵨ2.39⚪b>Ḅᩩ678᪀,\ᑏ^(x)=E“(x)-0(x)Ḅ`a,

298/⚗16ᙠḄi+,dᑖ᪆gḄ`aḄhijᩖl஺mn//^/⚗1ḄStatusPolyMinus(SqPoly&L,SqPoly&L1,SqPoly&L2)(PolyTerm*p,*pl,*p2;p=L.data;pl=Ll.data;p2=L2.data;inti=0,j=0,k=0;while(iexpexp){p->coef=pl->coef;p->exp=pl->exp;p++;k++;pl++;i++;)elseif(pl->exp>p2->exp){p->coef=-p2->coef;p->exp=p2->exp;p++;k++;p2++;j++;}else{if(pl->coef!=p2->coef){p->coef=(pl->coef)-(p2->coef);p->exp=pl->exp;p++;k++;)pl++;p2++;i++xj++x))if(icoef=pl->coef;p->exp=pl->exp;p++;k++;pl++;i++;}if(jcoef=-p2->coef;

30p->exp=p2->exp;p++;k++;p2++;j++;)L.last=k;returnOK;)ᙠ2.41'2.42⚪+,-./⚗12ᵨḄ⊤678᪀LinkedPoly>?@typedefstructPolyNode{PolyTermdata;structPolyNode*next;}PolyNode,*PolyLink;typedefPolyLinkLinkedPoly;2.41U⊤-./⚗1Ḅ678᪀,\ᑏ^ᐸᦪḄa,⌕^ᑭᵨ/⚗1+Ḅ8i6ᐸᦪ/⚗1,Whᡠᨵ¢ᵨ8஺mnStatusPolyDifferential(LinkedPoly&L){LinkedPolyp,q,pt;q=L;p=L->next;while(p!=L){if(p->data.exp==0){pt=p;p=p->next;q->next=p;free(pt);}else{p->data.coef=p->data.coef*p->data.exp;p->data.expqqxq=Pxp=p->next;))returnOK;)2.42U\ᑏ`a,qrᵨ⊤⊤¤Ḅ-./⚗1ᑖmᡂr/⚗1,¥¦r/⚗1+ᔜ¨©ª᜻¬⚗ᡈᏔ¬⚗,d⌕^ᑭᵨ⊤+Ḅ8i᪀ᡂ¦r⊤஺mn//ᓫ⊤Lᑜᑖᡂ2rᓫ⊤StatusListDivideInto2CL(LinkedPoly&L,LinkedPoly&L1)

31LinkedPolyp,pl,q,pt;q=L;p=L->next;pl=Ll;while(p!=L){if(p->data.exp%2==0){Pt=pxp=p->next;q->next=p;pt->next=pl->next;pl->next=pt;pl=pl->next;)else{q=p;p=p->next;returnOK;}´3µ᪘·ᑡ3.1¹ᢥᦟ¼½3.1.1⁚+¿3.1(b)ᡠ¤À⍝ÂÃÄÅÆl(ÇÈnÉÀ⍝ᙳ@ᓫᔣÃÌ⍝),ᑣuÎÏn(1)᝞ÂÑḄÄÅ5ᑡ@123,ᑣÒÓÔᑮḄÖÑÄÅ5ᑡ×ØÙÚ(2)᝞ÂÑḄÄÅ5ᑡ@123456,ᑣÓᔲÔᑮ435612135426ḄÖÑ5ᑡ,duÝÞ@ØÙßÓÔᑮᡈὅ᝞áÔᑮ(ᓽᑏÖ⊤¤Â᪘ã,⊤¤Ö᪘Ḅ᪘ä5ᑡ)஺mnপ123231321213132(2)ÒÔᑮ135426ḄÖÑ5ᑡ,æßÓÔᑮ435612ḄÖÑ5ᑡ஺ç@4356ÖÑÝÞ12Gèᙠ᪘+,1ßÒÓᐜê2Ö᪘஺3.2ëì᪘íឋ⊤Ḅï஺mníឋ⊤×ᐹᨵñWᱯឋḄᦪóᐗõḄqrᨵ▲5ᑡ஺᪘×▲>©ᙠ⊤÷ÂÃᐭᡈᑤ◀äḄíឋ⊤஺3.3ᑏÖúᑡû5üḄvÖ8(᪘ḄᐗõýþSElemType@char)஺voidmain()(StackS;charx,y;InitStack(S);x='c';y=%';Push(S,x);Push(S,'a');Push(S,y);

32Pop(S,x);Push(S,t5);Push(S,x);Pop(S,x);Push(S,'s');while(!StackEmpty(S)){Pop(S,y);printf(y);}printf(x);)#$stack3.4()*+,-Ḅ/0(᪘Ḅᐗ345SElemType7int)஺(1)statusalgol(StackS)(inti,n,A[255];n=0;whi1e(!StackEmpty(S)){n++;Pop(S,A[n]);}for(i=l;i<=n;i++)Push(S,A[i]);}(2)statusalgo2(StackS,inte)(StackT;intd;InitStack(T);while(!StackEmpty(S)){Pop(S,d);if(d!=e)Push(T,d);)while(!StackEmpty(T)){Pop(T,d);Push(S,d);))#$(1)᪘DḄᦪFᐗ3⌮H(2)᝞J᪘DKᙠᐗ3e,MᐸO᪘DP◀3.5ᎷS*STXᑖW⊤Yᐭ᪘T[᪘Ḅ\]ᑣ_᝱Ta᝱ᙳ7c᪘Ḅᐭ᪘T[᪘Ḅ\]dᑡf*⊤Y7gᵫSTXiᡂḄdᑡ஺kf*\]Ḅdᑡ7ᔠ-dᑡ(m᝞SXSX7ᔠ-dᑡSXXS7n-dᑡ)஺op[qᑖprdᑡ7ᔠ-dᑡᡈn-dᑡḄtuvᑣwxy$z{|}Ḅᔠ-(᪘\])dᑡ(~}tᐭdᑡ)|f0ᑮ}Ḅ[ᐗ3($ᙠᢣḄᐗ3|)dᑡ஺#$n{dᑡDSḄ{ᦪtrᜧXḄ{ᦪ஺Sz{ᔠ-dᑡ7$T1=S...X....S....T2=S...X....X....Ꮇrn{\]}On+1{\]7dᑡ|}Ḅ\]஺ᵫn{\]}ᦑz{᪘(|7᪘AஹB)ḄKᐰ}ᎷS᪘⚔ᐗ3ᙳ7a஺n+1{\]|}|T1Ḅn+1{\]7S,T2Ḅn+1{\]7X஺T17ᐭ᪘\]ᎷSMb£᪘ᑣT1Ḅ[¤dtrᐜb¦a§T2Ma

33⌨᪘ᑣᐸ[¤dtrᐜa¦b஺ᵫT1Ḅ[7……ba……,T2Ḅ[¤d7……ab……ªyz{|}Ḅᔠ-᪘\]dᑡḄ[ᐗ3Ḅdᑡtr|}஺3.6oxy$¬®᪘ᵫᐭdᑡ12…nᑮḄ[dᑡ7p32-p“±²ᐭdᑡḄt{᣸ᑡ´ᑣᙠ[dᑡD|f0[µ¶᪵Ḅ¸$KᙠḼiீj

34inti;i=n;while(i>l)cout«i—;)3Gvoidditui(intj){if(j>l){cout«j;ditui(j-1);)return;)3.10/IJᑡ⌴RMNᦋᑏQb⌴RMN஺voidtest(int&sum)(intx;cin»x;if(x==0)sum=0;else(test(sum);sum+=x;)cout«sum;)3Gvoidtest(int&sum)(Stacks;InitStack(s);intx;do(cin>>x;Push(s,x);}while(x>0);while(!StackEmpty(s)){Pop(s,x);sum+=x;cout«sum<

353.11klmᑡnᚮ᪘qrsᦪtuvḄwxynz{ᜐ஺3G᪘}~s▲Ḅឋ⊤ᐸ▲ᑴ}ᐕᙠ⊤Ḅ~=ᐭnᑤ◀஺mᑡ}~s▲Ḅឋ⊤ᐸ▲ᑴ}ᐕᙠ⊤Ḅ~=ᐭᙠ⊤Ḅ~=ᑤ◀஺3.12ᑏJNḄ(mᑡḄᐗuvQEIemTypeQchar)஺voidmain()(QueueQ;InitQueue(Q);charx=y=c';EnQueue(Q,h');EnQueue(Q,6r5);EnQueue(Q,y);DeQueue(Q,x);EnQueue(Q,x);DeQueue(Q,x);EnQueue(Q,a')While(!QueueEmpty(Q))(DeQueue(Q,y);cout«y;)cout«x;)3Gchar3.13klJḄ¡¢(᪘nmᑡḄᐗuvᙳQint)஺voidalgo3(Queue&Q)(StackS;intd;InitStack(S);while(!QueueEmpty(Q))(DeQueue(Q,d);Push(S,d);}while(!StackEmpty(S))(Pop(S,d);EnQueue(Q,d);)

363Gmᑡ⌮¥3.14¦1234CQ§mᑡḄᐭᑡ/ᑖ©2ª«JᩩḄᑡ:(1)¢ᵫᐭ▲Ḅ§mᑡ°ᑮ²³¢ᵫ▲Ḅ§mᑡ°ᑮḄᑡ஺(2)¢ᵫ▲Ḅ§mᑡ°ᑮ²³¢ᵫᐭ▲Ḅ§mᑡ°ᑮḄᑡ஺(3)´³¢ᵫᐭ▲Ḅ§mᑡ°ᑮ³¢ᵫ▲Ḅ§mᑡ°ᑮḄᑡ஺3.15Ꮇ¶·¸¹᪀»¼~½§ᔣ᪘ᓽᙠ~ÀᦪÁḄ¸¹ÂøᙠḼr½᪘ÅÆḄ᪘Çᑖ©¶ᙠᦪÁḄr½y஺/Èᑏ»¼q½§ᔣ᪘twsḄɽBCGÊËᓄinistack(tws)ஹᐭ᪘push(tws,i,x)n᪘pop(tws,i)Ḅ,ᐸiQ0ᡈ1,ᵨᑖ©ᢣѶᙠᦪÁrḄr½᪘ÒÓÔᢥMN(Ö/×Ø᝱ÚÛܶQÚÝ)ᡈÞᦪ¶ßqàBCᔜᨵãäᨵåy஺3GclassDStack(ElemType*top[2];ElemType*p;intstacksize;intdi;public:DStack(intm){p=newElemType[m];if(!p)exit(OVERFLOW);top[0]=p+m/2;top[l]=top[0];stacksize=m;)^DStack(){deletep;}voidPush(inti,ElemTypex)(di=i;if(di==0){if(top[0]>=p)*top[0]~=x;elsecerr<

37if(di==0){if(top[0]top[0])return*top[l]~;elsecerr<next;deletep;s.size—;))voidClearStack(Stack&s)(LinkTypep;while(s.top){p=s.top;s.top=p->next;

38deletep;s.size——;)}intStackLength(Stacks)(returns.size;)StatusStackEmpty(Stacks){if(s.size==O)returnTRUE;elsereturnFALSE;)StatusGetTop(Stacks,ElemType&e){if(!s.top)returnERROR;else{e=s.top->data;returnOK;))StatusPush(Stack&s,ElemTypee)(LinkTypep;p=newNodeType;if(!p)exit(OVERFLOW);p->next=s.top;s.top=p;p->data=e;s.size++;returnOK;)StatusPop(Stack&s,ElemType&e)(LinkTypep;if(s.top){e=s.top->data;p=s.top;s.top=p->next;

39deletep;s.size~~;)returnOK;)//÷᪘⚔ᑮ᪘ÇᵨVisitoÞᦪùᔊ᪘û½ᦪtᐗvoidStackTraverse(Stacks,Status(*Visit)(ElemTypee))(LinkTypep;p=s.top;while(p)Visit(p->data);)3.16Ꮇ¶᝞⚪3.1ᡠþÿḄᐭᜐᨵn⁚ᡈ(ᑖHS⊤)ᑏ!"#$%n⁚&'Ḅ()(ᓽᐭ᪘ᡈ#᪘()),ᑡ.ᡠᨵḄ01᦮ᑮ45஺78intmain(){Stacks;charBuffer[80];inti=0,j=0;InitStack(s);coutீ<஻U"ᐭ(H)ম,ᑡ8”Xcin>>Buffer;cout<

4078BOOLSymmetry(chara[])(inti=0;Stacks;InitStack(s);ElemTypex;while(a[i]!=&&a[i]){Push(s,a[i]);i++X}if(a[i])returnFALSE;i++Xwhile(a[i]){Pop(s,x);if(x!=a[ij){DestroyStack(s);returnFALSE;)i++X}returnTRUE;}3.18ᑏfgᑨ⊤y{ஹqᔲ$#Ḅ!஺78BOOLBracketCorrespondency(chara[])(inti=0;Stacks;InitStack(s);ElemTypex;while(a[i]){switch(a[i]){case'(':Push(s,a[i]);break;case':Push(s,a[i]);break;case')’:GetTop(s,x);if(x==(')Pop(s,x);elsereturnFALSE;break;

41case':GetTop(s,x);if(x=-)Pop(s,x);elsereturnFALSE;break;default:break;}i++X)if(s.size!=O)returnFALSE;returnTRUE;)3.20Ꮇ£¤¥ᦪ§g(l…m,1…n)⊤fgª«¬⊤¬{®(i,j)ᡠᐹ°⁐ᐸ²l³0ᑮkḄ᦮ᦪ஺ᑏ!´ᣚ®ᡠᙠ¬Ḅ°⁐஺·¸(i஺,j஺)¹⁐Ḅºஹ»ஹ¼ஹ½Ḅ¾¿®l¹⁐¬Ḅ®஺78Sincludettincludetypedefstruct{intx;inty;}PosType;typedefstruct{intColor;intVisited;PosTypeseat;}ElemType;Sinclude"d:\VC99\Stack.h"ttdefineM8#defineN8ElemTypeg[M][N];voidCreateGDS(ElemTypeg[M][N]);voidShowGraphArray(ElemTypeg[M][N]);voidRegionFi11ing(ElemTypeg[M][N],PosTypeCurPos,intNewColor);intmain()CreateGDS(g);

42ShowGraphArray(g);PosTypeStartPos;StartPos.x=5;StartPos.y=5;intFillColor=6;RegionFilling(g,StartPos,FillColor);cout<0&&!g[CurPos.x-1][CurPos.y].Visited&&g[CurPos.x-1][CurPos.y].Co1or==01dCo1or)Push(s,g[CurPos.x-l][CurPos.y]);if(CurPos.y0&&!g[CurPos.x][CurPos.y-1].Visited&&g[CurPos.x][CurPos.y-1].Color==01dColor

43)Push(s,g[CurPos.x][CurPos.y-1]);)voidCreateGDS(ElemTypeg[M][N])(inti,j;for(i=0;i

44i++Xwhile(Buffer[i]!='#'){if(!IsOperator(Buffer[i])){//q()ᦪBuffer[j]=Buffer[i];i++Xj++X)else{//q()oGetTop(s,e);if(Prior(e,Buffer[i])){//ä᪘⚔æᐜᩗéêä5,ᑡë⌨᪘Pop(s,e);Buffer[j]=e;j++X}else{Push(s,Buffer[i]);i++Xwhile(!StackEmpty(s)){Pop(s,e);Buffer[j]=e;j++X)StatusIsOpertor(charc)(char*p=஻#+_*/஻Xwhile(*p){if(*p==c)returnTRUE;p++X)returnFALSE;)StatusPrior(charcl,charc2)(charch□=஻#+-*/஻Xinti=0,j=0;while(ch[i]&&ch[i]!=cl)i++;if(i==2)i-;//ðñòólq¹ôḄÒo

45if(i==4)i-;//õ◀òólq¹ôḄÒowhile(ch[j]&&ch[j]!=c2)j++;if(j==2)j—;if(j==4)j—;if(i>=j)returnTRUE;elsereturnFALSE;}3.22᝞⚪3.21ḄᎷ£ᩩúᑏfg!$⌮Üᐲy⊤Ḅ⊤yû²஺78charCalVal_InverPoland(charBuffer[])(StackOpnd;InitStack(Opnd);inti=0;charc;ElemTypeel,e2;while(Buffer[i]!='#'){if(IlsOperator(Buffer[i])){Push(Opnd,Buffer[i]);)else{Pop(Opnd,e2);Pop(Opnd,el);c=Cal(el,Bufferti],e2);Push(Opnd,c);)i++X)returnc;charCal(charcl,charop,charc2)(intx,xl,x2;charch[10];ch[0]=cl;ch[l]=\0f;xl=atoi(ch);ch[0]=c2;ch[l]=\0";x2=atoi(ch);

46switch(op){case'+':x=xl+x2;break;case'-':x=xl-x2;break;case'*':x=xl*x2;break;case'/':x=xl/x2;break;default:break;)itoa(x,ch,10);returnch[0];}3.23᝞⚪3.21ḄᎷ£ᩩúᑏfg!ᑨüý¸Ḅþÿ⊤ᔲḄ⌮ᐲ⊤᝞ᑣᓄᐲ஺SincludettincludettincludeSinclude"d:\VC99\DSConstant.h"typedefcharARRAY[30];typedefARRAYElemType;typedefstructNodeType{ElemTypedata;NodeType*next;}NodeType,*LinkType;typedefstruct{LinkTypetop;intsize;}Stack;voidInitStack(Stack&s);StatusPush(Stack&s,ElemTypee);StatusPop(Stack&s,ElemTypee);StatusIsOperator(charc);StatusStackEmpty(Stacks);

47StatusInvToFroPoland(chara[]);intmainO(chara[30];cout<<஻STᐭ⌮ᐲVW⊤XYZᑡ\஻]cin>>a;if(InvToFroPoland(a))cout<=&&a[i]<='9'){ch[0]=a[i];ch[l]=\0>;Push(s,ch);)elsereturnFALSE;)else{ch[0]=a[i];ch[l]=\0J;if(IStackEmpty(s)){Pop(s,c2);if(!StackEmpty(s)){Pop(s,cl);strcat(ch,cl);strcat(ch,c2);Push(s,ch);)elsereturnFALSE;elsereturnFALSE;

48i++])if(IStackEmpty(s)){Pop(s,cl);strcpy(a,cl);)elsereturnFALSE;if(!StackEmpty(s))returnFALSE;returnOK;)voidInitStack(Stack&s){s.top=NULL;s.size=0;)StatusPush(Stack&s,ElemTypee){LinkTypep;p=newNodeType;if(!p)exit(OVERFLOW);p->next=s.top;s.top=p;strcpy(p->data,e);s.size++;returnOK;)StatusPop(Stack&s,ElemTypee){LinkTypep;if(s.top){strcpy(e,s.top->data);p=s.top;s.top=p->next;deletep;s.sizeߟ;)returnOK;)StatusStackEmpty(Stacks)if(s.size==0)returnTRUE;

49elsereturnFALSE;)StatusIsOperator(charc)(char*p=஻#+_*/஻]while(*p){if(*pppc)returnTRUE;p++])returnFALSE;)3.24qrᑏ᝞tuvḄ⌴xyᦪḄ⌴xV{|᪷~V{g(5,2)᪘Ḅᓄ஺/x0=0,஻20᝞஻)=஻?-1,2)+஻஻2ு0,஻20ZtJT•intg(intm,intn);intmainOintm,n;cout<ீ஻STᐭmnḄ\஻]cin>>m>>n;if(n>=0)cout«g(m,n)«endl;elsecout«zzNoSolution!;return0;)intg(intm,intn)(if(m>0)return(g(m-l,2*n)+n);elsereturn0;ᎷyᦪḄᙢᙬ0,⌴xyᦪ3ᩩḄᙢᙬᑖ1ஹ2ஹ3o3064313232163383440523.25qᑏ⌴xyᦪF(n)Ḅ⌴xV{|◀⌴x:

50[n4-1H=0£ಘ=|஻¦n>0\^includettdefineN20intmainO(inti;inta[N];intn;cout<ீ஻STᐭn:஻]cin>>n;for(i=0;ieᐸ¯PAḄ°±¨©᪷e²ᐕ´`µ஺qᑏ¶·Ḅ⌴xV{|◀⌴x஺\SincludedoubleSqrt(doubleA,doublep,doublee);intmain()(doubleA,p,e;cout<<“STᐭApe:஻]cin»A>>p»e;cout<"e&&(p*p-A)

51returnSqrt(A,(p+A/p)/2,e);3.27¼½AckermanyᦪḄuv᝞t

52+1m=0akm{m,n)=1){el.nval=e.aval;Pop(s,e);e.mval¿]e.nval=el.nval+1:

53}while(StackLength(s)!=11|e.mval!=0);returne.nval+1;}0,akm(2,1)021g=akm(2,0)l,akm(2,0)620akm=akm(m-1,l)=akm(l,1)2,akm(l,1)411g=akm(m,n-l)=akm(l,0)3,akm(l,0)610akm=akm(m-1,l)=akm(0,1)4,akm(0,1)401akm=n+l=2⌨᪘0,akm(2,1)021g=akm(2,0)1,akm(2,0)620akm=akm(m-1,l)=akm(l,1)2,akm(l,1)411g=akm(m,n-l)=akm(l,0)3,akm(l,0)610akm=akm(m-l,l)=akm(0,1)=2⌨᪘0,akm(2,1)021g=akm(2,0)1,akm(2,0)620akm=akm(m-1,l)=akm(l,1)2,akm(l,1)411g=akm(m,n-l)=akm(l,0)=2;akm=akm(m-1,g)=akm(0,2)3,akm(0,2)702akm=n+l=3⌨᪘0,akm(2,1)021g=akm(2,0)l,akm(2,0)620akm=akm(m-1,l)=akm(l,1)2,akm(l,1)411g=akm(m,n-l)=akm(1,0)=2;akm=akm(m-l,g)=akm(0,2)=3;⌨᪘0,akm(2,1)021g=akm(2,0)1,akm(2,0)620akm=akm(m-l,l)=akm(l,1)=3⌨᪘0,akm(2,1)021g=akm(2,0)=3;akm=akm(1,3)1,akm(l,3)613g=akm(1,2);akm(m-1,g)2,akm(l,2)612g=akm(l,1);akm(m-1,g)3,akm(l,1)611g=akm(1,0);akm(m-l,g)4,akm(l,0)610akm=akm(0,1)5,akm(0,1)401akm(0,1)=2⌨᪘0,akm(2,1)021g=akm(2,0)=3;akm=akm(l,3)1,akm(l,3)613g=akm(1,2);akm(m-1,g)2,akm(l,2)612g=akm(l,1);akm(nr1,g)3,akm(l,1)611g=akm(1,0);akm(m-1,g)4,akm(l,0)610akm=akm(0,1)=2⌨᪘

540,akm(2,1)021g=akm(2,0)=3;akm=akm(l,3)1,akm(l,3)613g=akm(1,2);akm(m-1,g)2,akm(l,2)612g=akm(l,1);akm(m-1,g)3,akm(l,1)611g=akm(1,0)=2;akm(m-1,g)=akm(0,2)4,akm(0,2)702akm=n+l=3⌨᪘0,akm(2,1)021g=akmফ0)=3;akm=akm(l,3)1,akm(l,3)613g=akm(1,2);akm(m-1,g)2,akm(l,2)612g=akm(l,1);akm(m-l,g)3,akm(l,1)611g=akm(l,0)=2;akm(m-1,g)=akm(0,2)=3⌨᪘0,akm(2,1)021g=akm(2,0)=3;akm=akm(1,3)1,akm(l,3)613g=akm(1,2);akm(m-1,g)2,akm(1,2)612g=akm(1,1)=3;akm(m-1,g)=akm(0,3)3,akm(0,3)703akm=n+l=4⌨᪘0,akm(2,1)021g=akm(2,0)=3;akm=akm(l,3)1,akm(l,3)613g=akm(1,2);akm(m-1,g)2,akm(l,2)612g=akm(l,1)=3;akm(m-l,g)=akm(0,3)=4⌨᪘0,akm(2,1)021g=akm(2,0)=3;akm=akm(l,3)1,akm(l,3)613g=akm(1,2)=4;akm(m-1,g)=akm(0,4)2,akm(0,4)704akm=n+l=5⌨᪘0,akm(2,1)021g=akm(2,0)=3;akm=akm(l,3)1,akm(l,3)613g=akm(1,2)=4;akm(m-1,g)=akm(0,4)=5⌨᪘0,akm(2,1)021g=akm(2,0)=3;akm=akm(1,3)=5⌨᪘akm(2,1)=5;3.28ᎷÂᜮ²ÄḄÅÆÇ⊤⊤ÈÉᑡ|ÊË¿Ìᢣ┐ᢣᔣÉÐᐗÒ²Ä(ÓÔÕᜮᢣ┐)qrᑏ¶·ḄÉᑡÖ×ᓄஹᐭÉᑡØᜐÉᑡḄV{஺typedefintElemType;typedefstructNodeType{ElemTypedata;NodeType*next;}QNode,*QPtr;typedefstruct{QPtrrear;intsize;}Queue;StatusInitQueue(Queue&q)

55q.rear=NULL;q.size=O;returnOK;)StatusEnQueue(Queue&q,ElemTypee)(QPtrp;p=newQNode;if(!p)returnFALSE;p->data=e;if(!q.rear){q.rear=p;p->next=q.rear;)else{p->next=q.rear->next;q.rear->next=p;q.rear=p;)q.size++;returnOK;)StatusDeQueue(Queuefeq,ElemType&e){QPtrp;if(q.size==0)returnFALSE;if(q.size==l){p=q.rear;e=p->data;q.rear=NULL;deletep;)else{p=q.rear->next;e=p->data;q.rear->next=p->next;deletep;)q.size]returnOK;)3.29᝞ᑡḄᐗᑮᑭᵨᑣ◤᪗!tag,"#tagḄ$%0&1ᩭ(ᑖ*ᢣ┐&ᜮᢣ┐$./0Ḅᑡ1᝱3“5”73“89:ᑏ<=>᪀.@Ḅᐭᑡ&BᑡḄCD"E0F&5FGHI

56Û᪗ÝÕ᪗ÝÞßà©{Ḅáᵨä(᝞åÅÆÉᑡæçèé¦Éᑡ¯êÌᐗÒᓰḄìíèîï¿à©{èð)஺\#defineMaxQSize4typedefintElemType;typedefstruct{ElemType*base;intfront;intrear;Statustag;}Queue;StatusInitQueue(Queue&q)(q.base=newElemType[MaxQSize];if(!q.base)returnFALSE;q.front=0;q.rear=0;q.tag=0;returnOK;)StatusEnQueue(Queue&q,ElemTypee){if(q.front==q.rear&&q,tag)returnFALSE;else{q.base[q.rear]=e;q.rear=(q.rear+l)%MaxQSize;if(q.rear==q.front)q.tag=l;)returnOK;)StatusDeQueue(Queue&q,ElemType&e){if(q.front==q.rear&&!q.tag)returnFALSE;else{e=q.base[q.front];q.front=(q.front+l)%MaxQSize;qtag=0;)returnOK;)᪗Ý⁚ḕõìíö÷øíèù஺Õ᪗Ýᑣð¶ú஺3.30ᎷÅÆÉᑡuv\ûçrearlengthᑖᢣÈÅÆÉᑡ¯ÉÐᐗÒḄüýᑁÿᐗḄᦪ஺ᑡḄᩩᑏḄᐭᑡᑡḄ(ᙠᑡḄ⌕ᜮᐗ)஺

57#$#defineMaxQSize4typedefintElemType;typedefstruct{ElemType*base;intrear;intlength;}Queue;StatusInitQueue(Queue&q){q.base=newElemType[MaxQSize];if(!q.base)returnFALSE;q.rear=O;q.length=0;returnOK;)StatusEnQueue(Queue&q,ElemTypee){if((q.rear+l)%MaxQSize==(q.rear+MaxQSize-q.length)%MaxQSize)returnFALSE;else{q.base[q.rear]=e;q.rear=(q.rear+1)%MaxQSize;q.length++;)returnOK;)StatusDeQueue(Queue&q,ElemType&e)(if((q.rear+MaxQSize-q.1ength)%MaxQSize==q.rear)returnFALSE;else{e=q.base[(q.rear+MaxQSize-q.length)%MaxQSize];q.length--;)returnOK;)3.31Ꮇ&'()*)+,Ḅ-./ᑡ0“ᦻ”4᝞ᓃbbaMabcbaM7ᦻᓃbcdeMᓃbababMᑣ97ᦻ஺ᑏ:ᑨ<)ᐭḄ:=W0>?.Ḅ-./ᑡ7ᔲ7“ᦻ”஺#$StatusSymmetryString(char*p)Queueq;

58if(!InitQueue(q))return0;Stacks;InitStack(s);ElemTypeel,e2;while(*p){Push(s,*p);EnQueue(q,*p);p++a)while(!StackEmpty(s)){Pop(s,el);DeQueue(q,e2);if(el!=e2)returnFALSE;)returnOK;)3.32ᑭᵨᑡlᑏmk▤opq᜿/ᑡsn+1⚗Ḅ⌕mu$vWmaxwv+1>max,ᐸmax0yz{Ḅ|ᦪ஺(}~$⚪ᡠᵨᑡḄ0k,ᑣᙠ᡻>?ᶇᙠᑡḄᐗ7ᡠmk▤opq᜿/ᑡḄᨬk⚗)#$intFibonacci(intk,intn)(if(k=k){//ᑡmx=sum(q);DeQueue(q,e);EnQueue(q,x);i++a)

59returnq.base[(q.rear+q.MaxSize-1)%q.MaxSize];)3.33ᙠ/>᪀¡¢£¤¥▲Ḅ§¨ᑡḄᐭᑡᑡ(©ᐕ«ᜮᑡ)஺&¬ᐗ⊤®:¯ᜐᳮḄ²³ᐗ´⊤®²³Ḅ⚜¶·஺ᐭᑡ¸¹ºᓄḄ¼²³½ᐜ¿ᑣÀ:ÁÂÃḄ²³Ḅ⚜¶᡻·ÄÅᜮƲ³ḄÇᙳ·ᑣÉᐭᙠᜮᔲᑣÉᐭᙠÆ஺#$//Filename:Queue,htypedefstruct{ElemType*base;intfront;intrear;Statustag;intMaxSize;}DQueue;StatusInitDQueue(DQueue&q,intsize)(q.MaxSize=size;q.base=newElemType[q.MaxSize];if(!q.base)returnFALSE;q.front=0;q.rear=0;q.tag=0;returnOK;)StatusEnDQueue(DQueue&q,ElemTypee)(if(q.front==q.rear&&q,tag)returnFALSE;if(q.front==q.rear&&!q.tag){//Îᑡq.base[q.rear]=e;q.rear=(q.rear+l)%q.MaxSize;if(q.rear==q.front)q.tag=l;)else{//ÏÎÏif(e<(q.base[q.front]+q.base[(q.rear+q.MaxSize-l)%q.MaxSize])/2){//Ðᜮᐭq.front=(q.front+q.MaxSize-l)%q.MaxSize;q.base[q.front]=e;if(q.rear==q.front)q.tag=l;}else{//ÐÆᐭq.base[q.rear]Ñe;q.rear=(q.rear+l)%q.MaxSize;

60if(q.rear==q.front)q.tag=l;returnOK;)StatusDeDQueue(DQueue&q,ElemType&e)(if(q.front==q.rear&&!q.tag)returnFALSE;else{//ÏÎᑡe=q.baseEq.front];q.front=(q.front+l)%q.MaxSize;q.tag=0;)returnOK;)//Filename:XT333.cppÓÔ/ᦻSincludeSincludetypedefintElemType;tiinclude஻D:\VC99\Queue.h஻intmain()(inttl,t2,t3,t4;ElemTypee;cout<ீ஻Û¤ᐭ²³alஹa2>a3>a4Ḅ᡻·$஻;cin»tl»t2»t3»t4;DQueuedq;InitDQueue(dq,5);EnDQueue(dq,tl);EnDQueue(dq,t2);EnDQueue(dq,t3);EnDQueue(dq,t4);while(dq.front!=dq.rearj|dq.tag){DeDQueue(dq,e);cout«e<

61ᐭᑡḄ஺intmain()(ElemTypee;DQueuedq;InitDQueue(dq,20);charch[20];cout«஻>?ᐭ@ABḄCDᑡ(E▲PHS):஻cin>>ch;inti=0;while(ch[i]){if(ch[i]==PP')cout«ch[i];if(ch[i]==PSP)EnDQueue(dq,ch[i],0);//Sᜮᐭif(ch[i]==PW)EnDQueue(dq,ch[i],1);//Sᐭi++)while(dq.front!=dq.rear||dq.tag){DeDQueue(dq,e);cout«e;}cout<

6244.1]^_`ᢣbcᡈec]^(ASCHṹh20H)iᡂḄ_Pk]_lmᨵop஺4.2_qr(StrAssign)ஹ_uv(StrCompare)ஹw_x(StrLength)ஹ_z{(Concat)ஹw|_(SubString)~᪀ᡂ_Ḅᨬ|஺4.6sl=SubString(s,3,1)s2=SubString(s,6,1)Replace(s,si,s2)Concat(s3,s,si)Concat(t,SubString(s3,1,5),SubString(s3,7,2))⚪//Filename:String,httincludeSincludeSdefineMaxSize128classString{char*ch;intcurlen;public:String(constString&ob);String(constchar*init);String();"String();voidStrAssign(Stringt);intStrCompare(Stringt);intStrLength();voidConcat(Stringt);StringSubString(intstart,intlen);voidshow();)String::String(constString&ob){ch=newchar[MaxSize+1];if(!ch)exit(1);curlen=ob.curlen;strcpy(ch,ob.ch);)String::String(constchar*init)(chnewchar[MaxSize+1];if(!ch)exit(1);

63curlen=strlen(init);strcpy(ch,init);}String::String()(ch=newchar[MaxSize+1];if(!ch)exit(1);curlen=O;ch[O]=\Of;)String::"String(){deletech;curlen=O;)voidString::StrAssign(Stringt)(strcpy(ch,t.ch);curlen=t.curlen;}intString::StrCompare(Stringt){returnstrcmp(ch,t.ch);)intString::StrLength()(returncurlen;)voidString::Concat(Stringt){strcat(ch,t.ch);curlen=curlen+t.curlen;)StringString::SubString(intstart,intlen)(Stringtemp;inti,j;if(start>=0&&start+len<=curlen&&len>0){temp.curlen=len;for(i=0,j=start;i

64)voidString::show()cout<=0;i—)t.Concat(s.SubString(i,1));s.StrAssign(t);)4.115ᦪi¡¢⊤5.1:(1)6X8X6=288Byte(2)LOC(5,7)=1000+(5X8+7)X6=1282(3)LOC(1,4)=1000+(1X8+4)X6=1072(4)LOC(4,7)=1000+(7X6+4)X6=12765.2:(1)LOC(O,0,0,0)=100(2)LOC(1,1,1,0=100+(1X3X5X8+1X5X8+1X8+1)X4=776(3)LOC(3,1,2,5)=100+(3X3X5X8+1X5X8+2X8+5)X4=1784(4)LOC(8,2,4,7)=100+(8X3X5X8+2X5X8+4X8+7)X4=44165.3:(0,0,0,0)(1,0,0,0)(0,1,0,0)(1,1,0,0)(0,0,1,0)(1,0,1,0)(0,1,1,0)(1,1,1,0)(0,0,2,0)(1,0,2,0)(0,1,2,0)(1,1,2,0)(0,0,0,1)(1,0,0,1)(0,1,0,1)(1,1,0,1)(0,0,1,1)(1,0,1,1)(0,1,1,1)(1,1,1,1)(0,0,2,1)(1,0,2,1)(0,1,2,1)(1,1,2,1)(0,0,0,2)(1,0,0,2)(0,1,0,2)(1,1,0,2)(0,0,1,2)(1,0,1,2)(0,1,1,2)(1,1,1,2)(0,0,2,2)(1,0,2,2)(0,1,2,2)(1,1,2,2)5.4k=£bᐸl,a=Max(i,j),b=Min(i,j)5.5k=ni-(n-j)-----------1(i>1,j>1,i>j)

65II,f,(i)=(n+-)i--i2f(j)=jc=-(n+l)5.6u=i-j+lv=j-l5.7পk=2(i-l)+j-l(|i-j|

665.13(1)List=((x,(y)),(((())),(0),(z)))(2)List=(((a,b,()),()),(a,(b)),())5.14s(n)=s(n-l)+a=s(n-l)+a1+(n-l)d(n>=l)nElemTypes(inti)(if(i>l)returns(i-l)+al+(i-l)*d;elsereturnal;)ab=05.16add(a,b)={add(++a,——b)b>05.17W:intMax(SqList&L,intk)(if(kMin(L,k+1))returnMin(L,k+1);

67elsereturnL.elem[k];elsereturnL.elem[k];)intSum(SqList&L,intk)(if(k==O)returnL.elem[O];elsereturnL.elem[k]+Sum(a,k-l);)intProduct(SqList&L,intk){if(k==0)returnL.elem[0];elsereturnL.elem[k]*Sum(a,k-l);)doubleAvg(SqList&L,intk)(if(k==0)returnL.elem[0];elsereturn(Avg(a,kT)*k+L.elem[k])/(k+1);)5.18ḄÚÛ`ÜᦪiᑖᡂkiPÜbiiÝÝÞᣚ,àÜbiÈiÝÝÞᣚP•.Pâᐳ◤n-kÅÞᣚ஺äåᨬæbiçèéêëkcᐗìḄíîPï«ᨬæbihᒕñᐗìÆbiḄòócᐗìᐳkc᪀ᡂᨬæbi஺voidRRMove(ElemTypeA[],intk,intn){ElemTypee;inti=0,j,p;while(i

685.19Sinclude#defineRS4#defineCS4typedefintElemType;typedefstruct(ElemTypee;inti,j;intFlags;}NodeType;voidInitialize(NodeTypea[RS][CS],ElemTypeA[RS][CS]);voidSaddlePoint(NodeTypea[RS][CS]);ElemTypeRowMin(NodeTypea[RS][CS],intk);ElemTypeColMax(NodeTypea[RS][CS],intk);voidShow(NodeTypea[RS][CS]);intmainO(ElemTypeA[RS][CS]=[{2,1,3,4},{1,3,1,2},{2,7,1,3},{3,2,4,1})NodeTypea[RS][CS]Initialize(a,A);SaddlePoint(a);Show(a);return0;}voidInitialize(NodeTypea[RS][CS],ElemTypeA[RS][CS])(inti,j;for(i=0;i

69)voidSaddlePoint(NodeTypea[RS][CS]){inti,j;ElemTypex,y;for(i=0;ia[k][i].e){x=a[k]Ei],e;}returnx;)ElemTypeColMax(NodeTypea[RS][CS],intk){ElemTypex;x=a[0][k].e;inti;for(i=l;i

70if(a[i][j].Flags)cout<

71);CSparseMat::CSparseMat(intr,intc,intn)(m_nRow=r;m_nCol=c;m_nTrs=n;m_pt=newTriple[m_nTrs];//?ᐭ°▣ḄᡠᨵÈᐗiinti;for(i=0;iTextOut(0+j*20,0+i*20,str,strlen(str));))}//°▣þÆḄÇÿᦪCSparseMatCSparseMat::operator+(CSparseMatB)(CSparseMattemp(mnRow,m_nCol,0);if(m_nRow!=B.m_nRow|im_nCo1!=B.m_nCo1)returntemp;

72temp.m_pt=newTriple[m_nTrs+B,m_nTrs];if(!temp.m_pt)returntemp;temp.m_nTrs=m_nTrs+B.mnTrs;inti=0;intj=0;intk=0;while(i

73temp.m_nTrs=k;returntemp;5.23#include#includeSdefineMax128typedefintElemType;typedefstruct{intcol;ElemTypee;}Twin;classCSparseMat(public:CSparseMat(){}CSparseMat(intr,intc,intn);virtual^CSparseMat(){}voidShowSparse(inti,intj);Twin*m_pt;//ᢣᔣ=>ᐗḄᢣ┐intrpos[Max]intmnCol;//B▣ᑡᦪintm_nRow;//B▣Eᦪintm_nTws;//=>ᐗFᦪ);CSparseMat::CSparseMat(intr,intc,intn)(m_nRow=r;m_nCol=c;m_nTws=n;m_pt=newTwin[m_nTws];if(!m_pt)return;//HᐭB▣ḄᡠᨵLᐗMinti;for(i=0;iᐗLᐗMḄᑡ᪗VW஻;cin>>m_pt[i].col>>m_ptEi],e;)for(i=0;i

74COUt«஻XHᐭYEZ[F=>ᐗᙠLᐗM]Ḅ^_(`ᨵHᐭ-1):஻;cin»rpos[i];//cE`ᨵ=>ᐗHᐭ-1)}voidCSparseMat::ShowSparse(inti,intj)(if(i>m_nRow||j>m_nCol)return;ElemTypex=0;ints,d;if(i==m_nRow){s=rpos[i];d=m_nTws;)else{s=rpos[i];intm=l;d=rpos[i+m];while(d<0){if(i+m=0){intk=s;while(k

75)5.26typedefintElemType;typedefstructOLNode{introw;intcol;ElemTypee;structOLNodebright,*down;}OLNode,*0Link;classCCrossListMat(public:OLink*RHead,*CHead;//Ekᑡᢣ┐ᔣlḄᜮᢣ┐intm_nCol;//B▣ᑡᦪintm_nRow;//B▣Eᦪintm_nNum;//=>ᐗFᦪpublic:CCrossListMat(){}CCrossListMat(intr,intc,intn);virtual^CCrossListMat(){}voidShowMat(inti,intj);)CCrossListMat::CCrossListMat(intr,intc,intn)(m_nRow=r;m_nCol=c;m_nNum=n;inti;RHead=newOLink[m_nRow];if(!RHead)exit(-2);CHead=newOLink[mnCol];if(!CHead)exit(-2);for(i=0;i

76cout«"XHᐭ=>ᐗḄE᪗ஹᑡ᪗VW஻;cin>>p->row>>p->col>>p->e;q=RHead[p->row];if(!q){RHead[p->row]=p;p->right=NULL;)else{qfLqwhile(q&&q->colcol){qf=qq=q->right;)p->right=qf->right;qf->right=p;}q=CHead[p->col];if(!q){CHead[p->col]=p;p->down=NULL;)else{qf=qwhile(q&&q->rowrow){qf=qq=q->down;}p->down=qf->down;qf->down=p;)))voidCCrossListMat::ShowMat(inti,intj)(ElemTypex=0;OLinkp;p=RHead[i];while(p&&p->col!=j)p=p->right;if(p)x=p->e;cout<

775.27#include#includetypedefintElemType;typedefstructOLNode{introw;intcol;ElemTypee;structOLNode*right,*down;}OLNode,*0Link;classCCrossListMat{public:OLink*RHead,*CHead;//Ekᑡᢣ┐ᔣlḄᜮᢣ┐intm_nCol;//B▣ᑡᦪintm_nRow;//B▣Eᦪintm_nNum;//=>ᐗFᦪpublic:CCrossListMat(){}virtual^CCrossListMat(){}CCrossListMat(intr,intc,intn);voidAdd(CCrossListMatB);voidShowMat();)CCrossListMat::CCrossListMat(intr,intc,intn)(m_nRow=r;m_nCol=c;m_nNum=n;inti;RHead=newOLink[m_nRow];if(!RHead)exit(-2);CHead=newOLink[mnCol];if(!CHead)exit(-2);for(i=0;i

78for(i=0;iᐗḄE᪗ஹᑡ᪗VW஻;cin>>p->row>>p->col>>p->e;q=RHead[p->row];if(!q){RHead[p->row]=p;p->right=NULL;)else{qf=q;while(q&&q->colcol){qf=q;q=q->right;}p->right=qf->right;qf->right=p;q=CHead[p->col];if(!q){CHead[p->col]=p;p->down=NULL;else{qf=q;while(q&&q->rowrow){qf=q;q=q->down;p->down=qf->down;qf->down=p;voidCCrossListMat::Add(CCrossListMatB)(inti,k=0;OLinkpa,pb;OLinkpre,p;//ᢥEuᐭOLinkqpre,q;//ᢥᑡuᐭfor(i=0;i

79pa=RHead[i];pb=B.RHeadEi];pre=NULL;while(pb){whi1e(pa&&pa->co1co1){pre=pa;pa=pa->right;}if(pa&&pa->col==pb->col){pa->e=pa->e+pb->e;pb=pb->right;pre=pa;pa=pa->right;}else{//ᙠA]uᐭ[Fvwxp=newOLNode;p->row=pb->row;p->col=pb->col;p->e=pb->e;pb=pb->right;if(!pre){p->right=pa;RHead[i]=p;)else{p->right=pre;pre->right=p;)//ᜐᳮᑡᢣ┐qpre=NULL;q=CHead[p->col];while(q&&q->rowdown;)if(!qpre){p->down=q;CHead[p->col]=p;}else{p->down=pre;pre->down;

80)k++;)}//endwhile(pb)}//endform_nNum=m_nNum+k;}voidCCrossListMat::ShowMat()(inti,j;OLinkp;for(i=0;irow==i&&p->col==j){cout<e<<{/;p=p->right;)elsecoutீீ0ீ<஻஻)cout«endl;))intmainO(CCrossListMatA(3,3,4),B(3,3,2);A.Add(B);A.ShowMat();return0;)~ᐵ⊤Ḅ#include"DSConst.h஻//lᜮᦻSinclude"StrStat.h{z//ᜮᦻ//⊤ᦪw᪀typedefcharAtomType;typedefenum{ATOM,LIST}ElemTag;typedefstructGLNode{ElemTagtag;

81union{AtomTypeatom;structGLNode*hp;)structGLNode*tp;}*GList;//=Strᑖᒘᡂ¡¢ᑖ{HStr£Z[F{TStr£¤¥Ḅ¦intStrDistrict(CString&Str,CString&HStr,CString&TStr)(intn,i,k;CStringsi;CStrings2(஻{஻){s3(஻(஻){s4(஻)஻)஻ln=Str.StrLength();i=lk=0;while(i<=n&&si.StrCompare(s2)||k!=0){sl=Str.SubString(i,1);if(!si.StrCompare(s3))k++;elseif(!sl.StrCompare(s4))k--;i++)if(i<=n){HStr=Str.SubStringd,i-2);TStr=Str.SubString(i,n-i+l);)else{HStr=Str;TStr.StrClear();)returnOK;//ᵨs©ª⊤LintCreateGList(GList&L,CString&s){CStringSub,HSub,TSub;஻¦{⊤ᜮ{⊤«if(s.StrEmpty())L=NULL;else{//={©ª⊤L=newGLNode;//¬[Fwxif(!L)exit(OVERFLOW);if(s.StrLength()>1){//᝞²³ᜧ1,µ⊤wxL->tag=LIST;

82Sub=s.SubString(2,s.StrLengthO-2);//¶·_ᑁ¦if(!Sub.StrEmpty()){//©ª¦⊤StrDistrict(Sub,HSub,TSub);if(!HSub.StrEmpty())//⊤ᜮ¹CreateGList(L->hp,HSub);elseL->hp=NULL;if(!TSub.StrEmpty())//⊤«¹CreateGList(L->tp,TSub);elseL->tp=NULL;}else{//⊤L->hp=NULL;L->tp=NULL;else{//©ªº¦wxL->tag=ATOM;L->atom=s.GetStr()[0];L->tp=NULL;returnOK;//»¼⊤voidShowGList(GList&L)(if(L){if(L->tag==LIST){cout«z/(஻if(L->hp)ShowGList(L->hp);if(L->tp){cout<<{z,{z;ShowGList(L->tp);)cout<<஻)஻)elsecout<atom;5.30://½⊤¾¿Ḅ⌴Á

83intGListDepth(GList&L)intDepth=O;intHDepth,TDepth;//⊤ᜮ¾¿{⊤«¾¿if(!L)returnDepth;//⊤¹Âᙠif(L->tag==ATOM)returnDepth;//º¦wx¾¿£0else{Depths;//⊤wx¾¿£1HDepth=Depth+GListDepth(L->hp);TDepth=Depth+GListDepth(L->tp);returnHDepth>TDepth?HDepth:TDepth;5.31//ᵫ⊤LÅᑴ⊤TintCopyGList(GList&T,GList&L){if(!L)T=NULL;else{T=newGLNode;if(!T)exit(OVERFLOW);T->tag=L->tag;if(L->tag=LATOM)T->atom=L->atom;else{CopyGList(T->hp,L->hp);CopyGList(T->tp,L->tp);))returnOK;)5.32://ᑨ¡⊤ᔲÉÊ{ÉÊËÌOK,ᔲᑣËÌFALSEStatusGListCompare(GList&LI,GList&L2){if(!Ll&&!L2)returnOK;//LIVL2ᙳ£⊤if((!Ll&&L2)||(LI&&!L2))returnFALSE;else{//LIVL2ᙳ=⊤if(Ll->tag==L2->tag){//⊤ÏឋÉÑif(Ll->tag==ATOM){//ᙳ£º¦wxif(Ll->atom==L2->atom)returnOK;elsereturnFALSE;}else{//ᙳ£⊤wxif(GListCompare(Ll->hp,L2->hp)&&

84GListCompare(Ll->tp,L2->tp))returnOK;//⊤ᜮஹ⊤«ᙳÉÑelsereturnFALSE;elsereturnFALSE;//⊤Ïឋ¹Ñ5.33:6᪛᪛6.1ÒÓ[Ô᪛ÖḄ×ᔠ£,,,,,,,,,},XÚÛÜÔ᪛{ÝÌÞᑡß⚪(1)áF᪷wxã(2)áäå¦wxã(3)áFwxGḄæçã(4)áäwxGḄἔᐜã(5)áäwxGḄê¦ã(6)áäwxEḄ¦ëã(7)ìäwxEḄ¦ëã(8)wxBVNḄíî_ᑖïðñã(9)᪛Ḅ¾¿óôã(10)~wxC£᪷Ḅ¦᪛Ḅ¾¿óôã6.2[Ô¿£2Ḅ᪛k[ÔLõ᪛ᨵö÷ïãLõ᪛⚩ᨵ^᪛•{ú¿£2Ḅ᪛ᑣûüᨵ^஺6.3þᑖïÚÛᐹᨵ3Ḅ᪛3Ḅ᪛Ḅᡠᨵ᝱஺6.4HḄk᪛ᨵ᝞ឋ!H"#Ḅ$%&'(ᐸ*ᔜ"#,$ᨵk-.'᪛஺᝞/ᢥ"12341678ᐰ:;<(=(1)ᔜ"ḄᦪA%BCD(2);<pḄḄ᱄(HIᙠ)Ḅ;<%BCD(3);<pḄḄ!iL'(HIᙠ)Ḅ;<%BCD(4);<pḄᨵMᐘOḄᩩQ%RSDᐸMᐘOḄ;<%BCDkH-1Tপ-k-\(2)᝞/p%ᐸWXḄᨬZḄ['(M[')(ᑣp]^᪷Ḅ(`%kḄ᦮ᦪb—(d᦮ᦪᓽᡠᙠḄfᦪ(,fk᪛(gh`WXḄ;<஺᝞/p%ᐸWXḄᨬᜧḄ['(j[')(ᑣp+k-1ᐸᨬZḄOO(l]^᪷(◀nk,ᓽᐸWXḄ;<஺pᔠᩭs(8tp%j['Ḅuv(i=(p+k-2)/ky8tp%M['Ḅuv(i=(p-l)/k᝞/j['Ḅ;<P(ᑣᐸM[';<|p+k-1,ᡠn(ᐸWXḄ;<

85i=ᓃ+k2ᔣ~᦮(᝞1,5ᔣ~᦮1L᝕(3)pḄM['Ḅ;<kp+1,j['Ḅ;<kp+l-k+l=k(p-l)+2,!i['Ḅ;<k(p-l)+2+i-l=kp-k+i+lo(4)(pT)%k!=0:pᨵMᐘO(ᐸMᐘOḄ;<p+1஺6.5kḄ᪛ᨵ1Ḅ(%2Ḅ(…(4kḄ(=d᪛ᨵBC&'DT᪷᪛Ḅ(ᙠ⚩᪛(◀᪛᪷᜜(,ᨵᨵ(%s(,ᢣᔣḄᑖ8`(ᡠn◀᪛᪷᜜Ḅ᪛tᡠᨵḄᑖᦪ(ᓽᦪ(4᪛ḄᦪtᡠᨵḄᦪ1஺ᦪ1+/+2n+3%+.+k/20Ḅᦪ`ᦪ]^0ḄᦪḄ(ᓽk஻0=1+஻]+2஻2+3஻3+•••+kn-(«,+஻2+¢3+…+%)=1+Z('-k1=16.6ᙠ£ᨵnḄ᪛(¤ᨵkḄᑖ0Ḅ&'஺¥¦d᪛£ᨵḄ&'⁚ᦪA஺Tᑭᵨ#⚪«᧕/஺kḄᦪ⚗(ᑣᦪ஻=1+%¯஺&'ḄᦪA`tᦪ]^஺ḄḄᦪA(ᓽn-1n=n-n=n—0kk6.7£ᨵnḄk᪛(°±ᑮḄᨬᜧᨬZᔜBCDT°±ᑮᨬᜧḄ᪛%ᓫ᪛(ᐸn஺k᪛ḄᨬZ(ᐸFlog,-1)+1)!(´µ¶·¸¹℉ᦪ᪀¼ᵨᦟ¾P166)6.8´µk᪛#Ḅ&'ᦪ஻஺-&'ᦪ஽ÀÁnᐵÃn=(k-1)/1,+10T:஺k᪛ḄᨬÄ"(h)Ḅᦪ(&'ᦪ)஻0=,ᐸᦪ~_ᑣ1-&'ᦪ஻k~1'஻-1஺=Ækn-1-஻஺(4I'k-\0&-10n=(k—l)n,+10

866.9¥ᑖÈÉÊ£ᨵn£஻஺&'ḄÌᐰÍ᪛ḄH»T(1)᪷ÌᐰÍ᪛Ḅ3H-'-1<2M<3W-1k-lk-\2»+l<3w<3(2஻+1)log(2n+l)

87⊤>?஺ᎷABCᢣ┐Fᓰ4CI⁚BC67FᓰkCI⁚஺LMN>OPᨵnC+RḄ#$᪛Sᙠ'()*+᪀-ᨬUC⁚RḄV᪗Xm,ᙠ[\ᩩ^V'()*+᪀_;$<⊤`⁚ḕbcdeNfᵨ;$<⊤+᪀◤⌕n(k+12)CI⁚Ḅ)*bc஺fᵨ'()*+10M᪀◤⌕mkCI⁚Ḅ)*bcᑣmkீn(k+12)ᓽkl--fᵨ'(m-n)*_fᵨ;$<⊤`⁚ḕbc஺6.12>⚪6.3ᡠᔜqr᝱Ḅ#$᪛ᑖuᑏwx(ஹ-(:U(zᔊḄ(ᑡ஺6.13ᎷAn:mX#$᪛-}+Rᵨ1ஹ0ᡈ#(ᑖu⊤ஹាាᡈ)ᑏV⊤N9x(zᔊ-(zᔊU(zᔊnᙠmxdnᙠmxdnᙠmxdnᙠmnᙠmnmἔᐜnmN᝞পa:bᨬḄᐳἔᐜp)ᙠS(2)aᙠpḄ᪛-bᙠPḄ᪛-ᑣaᙠbḄ(ᓽbᙠaḄ)஺6.14wᡠᨵ¡¢Vᑡᩩ^Ḅ#$᪛N(a)£¤ᙠᐜ(zᔊ:-(zᔊᑮḄ⁚R¥M(ᑡ¦(b)£¤ᙠU(zᔊ:-(zᔊᑮḄ+R¥M(ᑡ¦(c)£¤ᙠᐜ(zᔊ:U(zᔊᑮḄ⁚R¥M(ᑡ஺eN(a)2᪛Ḅ#$᪛஺(b)2᪛Ḅ#$᪛஺(c)ᓽ2᪛2᪛Ḅ#$᪛஺6.15e:6.16eN1234567891011121314InfoABCDEFGHIJKLMNLtag00010101001111Lehi246273101412131391011IdRtag00110001110111

88Rchi3565891131213140118Id6.17eNᐸ┯ÁᙠO-(zᔊ?ᐜ¥Mᐸ᪛9Â᝞VÃᦋNBiTreeInSucc(BiTreeq){//Ìqᢣᔣ-(ÎÏ#$᪛0ÐC+RḄᢣ┐//ÑÒᦪÔÕᢣᔣ*qḄU×Ḅᢣ┐஺r=q->rchild;if(!r->ltag)while(!r->ltag)r=r->lchild;returnr;}//InSucc6.18eN᝞p᪷+RᑣᐸU×Xb஺ᔲᑣ◤ßpḄ45+R஺àp+Ráâ-(ÎÏzᔊ᝞Ð+RḄᢣ┐FãOPäå+RPḄ45+RSP£Ḅæ¦᝞Ð+RḄᢣ┐FãOPäå+RpḄ45+RSp£Ḅæ¦᝞ᓽ9ç¥Mè(஺éæᐸU×45+R¦éæᐸU×ᐸᐘëᨬVḄ᝞ᐘë)ᙠᐸU×ᐸ45+R஺6.19ᑖuìw:Vᑡ᪛>?ḄᔜC#$᪛N(1)ᐜ(N123456879101112131514

89(2)-(N348675211091115141312(3)U(N8765432101514131211916.23eN᪛Ḅᐜ᪷(ᑡXGFKDAIEBCHJ,U᪷(ᑡXDIAEKFCJHBG,9îᐜïᓄᡂ#$᪛ñòó#$᪛ïᣚᡂ᪛஺õ#$᪛Ḅᐜ᪷(ᑡöã÷᪛Ḅᐜ᪷(ᑡ#$᪛Ḅ-((ᑡ>?Ḽ᪛ḄU᪷(ᑡ஺GFKDAIEBCHJXᡠø#$᪛Ḅᐜ((ᑡDIAEKFCJHBGX#$᪛Ḅ-((ᑡ஺òóùúᐜ((ᑡGX#$᪛Ḅ᪷+Rñᵫ-((ᑡGḄ᪛(ᑡXDIAEKFCJHB,Xb஺9î⊤ᡂ᝞VrûNG(DIAEKFCJHB,NULL)>O᪛ᐜ((ᑡXFKDAIEBCHJ,-((ᑡXDIAEKFCJHB,ýᯠ᪛᪷XF஺ñᵫ-((ᑡ9îÿᑮFḄ᪛DIAEK,᪛CJHB஺⊤ᡂG(F(DIAEK,CJHB),NULL)#$DIAEK(%&⊤)ᐜ&KDAIE,K᪷DIAE,)*#$CJHB,B᪷CJH,)஺⊤ᡂG(F(K(DIAE,NULL),B(CJH,NULL)),NULL)G(F(K(D(NULL,IAE),NULL),B(C(NULL,JH),NULL)),NULL)G(F(K(D(NULL,A(I,E)),NULL),B(C(NULL,H(J,NULL)),NULL)),NULL)ᵫ,-./0᪛1-.᪛஺6.2445⚪789:ᑡ<ᣚ:树森林二树先根先序先序•后根制序相予“6.254*ᵨCDEFG஺Hn=2K⌕MᐸᡂᨬP/0᪛QRMSTUVWᡂXUV஺Yn=kKᡂ[ᑣHn=k+lK⌕MᐸᡂᨬPQRᵨkTUVḄ_`a᪛bck+1TUVeᡂTfḄᨬP/0᪛ᡠhn=k+lKiᡂ[஺

906.264opYq8TUVAஹBஹCஹDஹEஹFஹGஹH,ᐸk7Ḅᩗ7ஹ19ஹ2ஹA:1101B:01D:1110E:10F:11110G:00H:1100tᵨquvwxṹᵯᦻᨬ|஺6.2746.334intVisit(intu,intv)if(u==v)return1;if(L[v]==0){஻᪛oᙠif(R[v]==0)஻᪛ioᙠreturn0;else{//᪛ᙠ᪛if(Visit(u,R[v]))return1;elsereturn0;))else{//᪛ᙠif(Visit(u,L[v]))//᪛%ᙠ᪗return1;else{//᪛%ᨵ᪗◤᪛if(R[v]==0)//ᨵ᪛return0;else{//᪛ᙠ᪛if(Visit(u,R[v]))return1;elsereturn0;

916.344:intVisit(intu,intv)(intNv;Nv=NumElem(v);//UVvḄ:᪗if(Nv==-1)exit(-2);//UVvoᙠ⌨.if(u==v)return1;if(L[Nv]==O){஻᪛oᙠif(R[Nv]==0)஻᪛ioᙠreturn0;else{//᪛ᙠ᪛if(Visit(u,R[Nv]))return1;elsereturn0;})else{//᪛ᙠif(Visit(u,L[Nv]))//᪛%ᙠ᪗return1;else{//᪛%ᨵ᪗◤᪛if(R[Nv]==0)஻ᨵ᪛return0;else{//᪛ᙠ᪛if(Visit(u,R[Nv]))return1;elsereturn0;)})}//UVᙠᦪeT%Ḅ:᪗intNumElem(intx){inti=0;while(i

92//a᪷UVb᪛c᪛...//³´UVxµ᜻ᦪ//ᑣ·Qᐸ¸¹Ḅºᔲᑣº//xµkḄUVḄ¸¹UVḄxµk/2intNumTree(charc);//¼UVᙠ᪛%ḄxµintExp(inta,intb);//¼aḄb¾vintNumElem(charc);//ᐗÀᙠᦪe%Ḅ:᪗intmain(){charc;cout<<”ÃÄᐭUVḄÆ”*cin>>c;cout<

93x=x*a;returnx;)//UVᙠᦪeT%Ḅ:᪗intNumElem(charc)(inti=0;while(ilchild,T2->lchild)&&SimilarTree(Tl->rchild,T2->rchild))returnTRUE;elsereturnFALSE;6.374//ᐜ&ÒᔊḄÑ⌴CÕEStatusPOTraverse(BiTree&T,Status(*Visit)(TElemTypee)){BiTreep;Stacks;InitStack(s);P=T;while(pI|IStackEmpty(s)){if(p){//᝞É᪷ᢣ┐o)᪷UV//ᢣ┐ÛÜ᪘Òᔊ᪛if([Visit(p->data))returnERROR;Push(s,p->rchiId);p=p->lchild;

94}//᪷ᢣ┐Þ)5᪛ÞÒᔊßà//⌨᪘áâÒᔊãäḄUVelsePop(s,p);)returnOK;)6.414//¼å$ᐜ&&ᑡ%ckTåæḄUVḄÆ//e%çUVḄÆièᦪᘤStatusPONodeK(TElemType&e,int&i,intk,BiTreefeT)(if(T){i++*if(i==k)e=T->data;else{PONodeK(e,i,k,T->lchild);PONodeK(e,i,k,T->rchild);returnOK;)6.424//¼/0᪛%XUVḄᦪStatusPOLeafNodeNum(int&i,BiTree&T){if(T){if(!T->lchild&&!T->rchild)i++;POLeafNodeNum(i,T->lchild);POLeafNodeNum(i,T->rchild);)returnOK;}6.434//ᢥᐜ&ëᣚ/0᪛Ḅ᪛StatusExchangeBiTree(BiTree&T)(BiTreep;if(T){p=T->lchild;T->lchild=T->rchild;T->rchild=p;ExchangeBiTree(T->lchiId);ExchangeBiTree(T->rchiId);)

95returnOK;)6.444//¼/0᪛%hᐗÀÆXḄUV᪷Ḅ᪛ḄíîStatusChiIdTreeDepth(BiTree&T,TElemTypex,int&depth){BiTreeT1;if(PreOrderLocate(T,x,Tl)){depth=BiTDepth(Tl);returnOK;)elsereturnERROR;)//ᢥᐜ&ᙠ᪛%ïð᪷xḄ᪛Tlᢣᔣ᪛᪷Ḅᢣ┐StatusPreOrderLocate(BiTree&T,TElemTypex,BiTree&Tl){if(T){if(T->data==x){T1=T;returnOK;)else{if(PreOrderLocate(T->lchild,x,Tl))returnOK;else{if(PreOrderLocate(T->rchild,x,Tl))returnOK;elsereturnERROR;elsereturnERROR;)//¼/0᪛ḄíîintBiTDepth(BiTree&T){intIdep,rdep;if(!T)return0;else{ldep=BiTDepth(T->lchild)+l;rdep=BiTDepth(T->rchild)+l;returnldep>rdep?ldep:rdep;

966.454://ᑤ◀hᐗÀÆxḄUV᪷Ḅ᪛StatusDelChildTree(BiTree&T,TElemTypex)(if(T){if(T->data==x){DelBTree(T);T=NULL;returnOK;)else{if(DelChildTree(T->lchild,x))returnOK;else{if(DelChildTree(T->rchild,x))returnOK;elsereturnERROR;elsereturnERROR;)//ᑤ◀/0᪛StatusDelBTree(BiTree&T)(ifCD{DelBTree(T->lchild);DelBTree(T->rchiId);deleteT;returnOK;)elsereturnERROR;}6.464//õᑴ÷/0᪛StatusCopvBiTree(BiTreefcT,BiTree&Tl)(BiTreep;if(T){p=newBiTNode;if(!p)returnERROR;p->data=T->data;

97Tl=p;CopyBiTree(T->lchiId,Tl->lchild);CopyBiTree(T->rchiId,Tl->rchild);)else{T1=T;)returnOK;)6.474typedefBiTreeQElemType;Sinclude஻c:\Yin\include\Queue.h஻StatusLevelOrderTraverse(BiTree&T,Status(*Visit)(TElemTypee)){QElemTypep;Queueq;InitQueue(q);if(T)EnQueue(q,T);while(!QueueEmpty(q)){DeQueue(q,p);Visit(p->data);if(p->lchild)EnQueue(q,p->lchild);if(p->rchild)EnQueue(q,p->rchild);)returnOK;)6.484//ᙠ/0᪛T%¼UV*pü*qḄᐳþᨬÿἔᐜeStatusMinComAncst(BiTree&T,TElemType&e,TElemType*p,TElemType*q)(if(!T)returnERROR;BiTreeT1,T2,pt=NULL;if(ICopyBiTree(T,Tl))returnERROR;if(ICopyBiTree(T,T2))returnERROR;if(!PathTree(Tl,p))returnERROR;//-᪷/0ᑮ/0pḄ34᪛TlelseShowBiTree(Tl);cout<data==T2->data){

98pt=Tl;if(Tl->lchild){Tl=Tl->lchild;T2=T2->lchild;)else{if(Tl->rchild){Tl=Tl->rchild;T2=T2->rchild;)))if(!pt)returnERROR;else{e=pt->data;returnOK;))//ᙠ>?᪛T@-᪷ᑮ/0pḄ34᪛ABCDEFG◀34I᜜ḄᡠᨵᑖNStatusPathTree(BiTree&T,TElemType*p)(if(!T||!p)returnERROR;if(T->data==*p){//PᑮQ᪗Aᑤ◀Q᪗ḄTUV᪛if(T->lchild)DelBiTree(T->lchild);if(T->rchild)DelBiTree(T->rchild);returnOK;)else{//XPᑮQ᪗AYZ⌴\]Pif(PathTree(T->lchiId,p)){//Q᪗ᙠTV᪛@,ᑤ◀UV᪛if(T->rchiId)DelBiTree(T->rchiId);returnOK;}elseif(PathTree(T->rchiId,p)){//Q᪗ᙠUV᪛@Aᑤ◀TV᪛if(T->lchild)DelBiTree(T->lchiId);returnOK;)elsereturnERROR;//P_ᑮQ᪗6.49deStatusCompleteBiTree(BiTree&T)intd;

99if(T){d=BiTDepth(T->lchiId)-BiTDepth(T->rchild);if(d<0||d>l)returnERROR;else{if(CompleteBiTree(T->lchiId)&&CompleteBiTree(T->rchild))returnOK;elsereturnERROR;})elsereturnOK;)6.51LMStatusShowBiTExpress(BiTree&T){if(T){if(T->lchild){if(Low(T->lchild->data,T->data)){cout<<,C;ShowBiTExpress(T->1child);cout<<,);)elseShowBiTExpress(T->lchiId);)cout«T->data;if(T->rchild){if(Low(T->rchild->data,T->data)){coutNீ‘('ShowBiTExpress(T->rchiId);cout«')';}elseShowBiTExpress(T->rchiId);))returnOK;}StatusLow(chara,charb){if((a='+'||a='-')&&(b='||b'/'))returnTRUE;elsereturnFALSE;)6.52LMintBiTreeThrive(BiTreefeT)

100inti,d,nn[20];d=BiTDepth(T);BiTreep=T;Stacksi,s2;InitStack(sl);InitStack(s2);for(i=0;i<20;i++){nn[i]=O;//op/0qᦪ)if(p)Push(si,p);elsereturn0;for(i=0;ilchild)Push(s2,p->lchild);//s2@stui+1p/0if(p->rchild)Push(s2,p->rchild);))else{if(StackEmpty(si)&&IStackEmpty(s2)){while(!StackEmpty(s2)){Pop(s2,p);nn[i]++;if(p->lchild)Push(si,p->lchild);if(p->rchild)Push(si,p->rchild);intmax=nn[0];for(i=0;ilchild)!=1)DelBiTree(T->lchild);elseMaxPathBiTree(T->lchild);if(BiTDepth(T)-BiTDepth(T->rchild)!=1)

101DelBiTree(T->rchiId);elseMaxPathBiTree(T->rchiId);)returnOK;}//v᪷ᑮwVᨬy34@ᨬTzḄ34᪛StatusLMaxPathBiTree(BiTree&T)(if(BiTDepth(T)-BiTDepth(T->lchild)==l){DelBiTree(T->rchiId);LMaxPathBiTree(T->lchiId);)else{DelBiTree(T->lchild);if(BiTDepth(T)-BiTDepth(T->rchild)==l)LMaxPathBiTree(T->rchiId);elseDelBiTree(T->rchild);returnOK;)6.54de//᪷{|ᐰ>?~᪛|ᐰ>?⊤᪛StatusCreateCompleteBiTree(SqList&ST,BiTree<){BiTreep;inti=0,len;if(ST.Length==0)returnOK;p=newBiTNode;if(!p)returnERROR;p->data=ST.Get(i);p->lchild=NULL;p->rchild=NULL;LT=p;Queueq;InitQueue(q);EnQueue(q,p);len=ST.Length();while(!QueueEmpty(q)&&i

102DeQueue(q,p);if(ilchild=newBiTNode;if(!p->lchild)returnERROR;p->lchild->data=ST.Get(++i);p-ுIchiId->IchiId=NULL;p->lchild->rchild=NULL;EnQueue(q,p->lchild);}if(irchild=newBiTNode;if(!p->rchild)returnERROR;p->rchild->data=ST.Get(++i);p->rchild->lchild=NULL;p->rchild->rchild=NULL;EnQueue(q,p->rchild);})returnOK;}6.55deStatusPreOrderTraverse(BiTree&T)(ifCD{T->DescNum=DescendNum(T);PreOrderTraverse(T->lchiId);PreOrderTraverse(T->rchiId);)returnOK;)intDescendNum(BiTree&T){if(!T)return0;if(!T->lchild){if(!T->rchild)return0;elsereturnDescendNum(T->rchild)+1;)else{if(!T->rchild)returnDescendNum(T->lchild)+1;elsereturnDescendNum(T->rchiId)+DescendNum(T->lchiId)+2;6.56d:

103ᐜ>?᪛TᐜAᑮᐜ>?᪛Thrt஺ᯠ]P஺//ᐜ>?᪛StatusPreOrderThreading(BiThrTree&Thrt,BiThrTree&T){BiThrTreepre;Thrt=newBiThrNode;//>?᪛ᜮ/0if(!Thrt)exit(OVERFLOW);Thrt->LTag=Thread;Thrt->RTag=Link;Thrt->lchild=Thrt;//TV᪛ᢣif(!T)Thrt->rchild=Thrt;//>?᪛AUV᪛ᢣelse{Thrt->rchild=T;pre=Thrt;PreThreading(T,pre);//ᐜᔊᐜᓄpre->rchild=Thrt;//ᨬ¢q/0ᓄpre->RTag=Thread;Thrt->lchild=pre;)returnOK;)StatusPreThreading(BiThrTree&T,BiThrTree&pre)(if(T){if(!T->lchild){T->LTag=Thread;T->lchild=pre;)if(pre&&!pre->rchild){pre->RTag=Thread;pre->rchild=T;}pre=T;if(T->LTag==Link)PreThreading(T->lchiId,pre);if(T->RTag==Link)PreThreading(T->rchild,pre);}returnOK;//v>?᪛£¤¢/0q¥¦]P/0*P஺//᝞¨PᑮAE*PḄY/0ᢣ┐sªq@A«TRUE¬ᔲᑣ«FALSEStatusFindNextlnBiThrTree(BiThrTree&q,TElemType*p)

104BiThrTreept=q;if(!pt)returnFALSE;if(pt->data==*p){if(pt->LTag==Link)q=pt->lchild;elseq=pt->rchild;returnOK;)pt=q->rchild;while(pt!=q&&pt->data!=*p){if(pt->LTag==Link)pt=pt->lchild;elsept=pt->rchild;)if(pt==q)returnFALSE;if(pt->data==*p){if(pt->LTag==Link)q=pt->lchild;elseq=pt->rchild;)returnOK;}6.57deStatusPostOrderThreading(BiThrTree&T,BiThrTree&pre);஻✌ᐜ᪛StatusFindNextlnBiThrTree(BiThrTree&q,TElemType*p);஻]P//>?᪛ḄStatusPostOrderThreading(BiThrTreefeThrt,BiThrTreefeT)(BiThrTreepre;Thrt=newBiThrNode;//>?᪛ᜮ/0if(!Thrt)exit(OVERFLOW);Thrt->LTag=Link;Thrt->RTag=Thread;Thrt->rchild=Thrt;//UV᪛ᢣif(!T)Thrt->lchild=Thrt;//>?᪛ATV᪛ᢣelse{Thrt->lchild=T;pre=Thrt;PostThreading(T,pre);//ᔊᓄpre->rchild=Thrt;//ᨬ¢q/0ᓄpre->RTag=Thread;Thrt->rchild=pre;)returnOK;

105StatusPostThreading(BiThrTree&T,BiThrTree&pre)(if(T){if(T->LTag==Link)PostThreading(T->lchiId,pre);if(T->RTag==Link)PostThreading(T->rchild,pre);if(!T->lchild){T->LTag=Thread;T->lchild=pre;)if(pre&&!pre->rchild){pre->RTag=Thread;pre->rchild=T;)pre=T;)returnOK;)6.58d:typedefcharTElemType;typedefstructCSNode{TElemTypedata;structCSNode*firstchild,*nextsibling;}CSNode,*CSTree;//᪛Ḅ>?⊤⊤±StatusCreateTree(CSTree&T)(charch;cout«஻²ᐭ/0Ḅ´(¢qµ¶A⊤±᪛)஻¬cin»ch;if(ch==A){T=NULL;)else{T=newCSNode;if(!T)returnERROR;T->data=ch;CreateTree(T->firstchiId);CreateTree(T->nextsibling);)returnOK;)//²¸᪛ḄᔜºStatusShowTree(CSTree&T,CSTree&Father)

106if(T&&Father)cout«/zCA<data<data<firstchild)ShowTree(T->firstchild,T);if(T->nextsibling)ShowTree(T->nextsibling,Father);returnOK;}6.60deintLeafNum(CSTree&T)(if(T){if(!T->firstchild)return1+LeafNum(T->nextsib1ing);elsereturnLeafNum(T->firstchild)+LeafNum(T->nextsibling);)elsereturn0;)6.61deintDegreeNum(CSTree&T)(intd,dl,dr;if(T){if(!T->firstchild)d=0;elsed=l+RSiblingNum(T->firstchild);dl=DegreeNum(T->firstchiId);dr=DegreeNum(T->nextsibling);returnMax(d,dl,dr);//¼ᦪ@-ᨬᜧὅ)elsereturn0;)//«¿À/0ḄᐘÂᦪintRSib1ingNum(CSTree&T)(inti=0;while(T->nextsibling){i++¬T=T->nextsibling;)returni;)6.62d://᪛ḄÃÄintDepth(CSTreefeT)

107intdl,d2;if(T){dl=l+Depth(T->firstchiId);d2=Depth(T->nextsibling);returndl>d2?dl:d2;}elsereturn0;)77.1de(1)ID(1)=3OD(1)=OID(2)=20D(2)=2ID(3)=10D(3)=2ID(4)=10D(4)=3ID(5)=2OD(5)=1ID(6)=20D(6)=3ফ000000100100010001001011100000110010ব(4)(5)ᨵ¼qÉÊᑖË1ஹ5ஹ23467.2dek=l,ÍÎÏᔜ/0IÐḄÑÒÉÊᐵÔ;ÍÎÏ/0IÐᢥ34yÄ2ḄÑÒÉÊᐵÔ¬..…7.3deÖ×⊤e

108Ö×ÙÚ⊤:ÃÄÛᐜÜḄ~156432ÝÄÛᐜÜḄ~156324,15161312247.14deStatusCreateAG(ALGraph&G)(intn,e,k,i,j;cout<<஻ß²ᐭ⚔0ᦪe”¬cin>>n;COUt஺”ß²ᐭºᦪe”¬cin>>e;G.vernum=n;G.arcnum=e;//⚔0ᦪâfor(k=0;k>G.vertices[k].data;G.vertices[k].firstarc=NULL;)//Ö×⊤VertexTypevl,v2;ArcNode*p,*q;for(k=0;k>vl>>v2;

109i=LocateVex(G,vl);if(i<0||i>G.vernum-1)returnERROR;j=LocateVex(G,v2);if(j<0||j>G.vernum-1)returnERROR;if(i==j)returnERROR;p=newArcNode;if(!p)returnERROR;p->adjvex=j;p->nextarc=NULL;q=G.vertices[i].firstarc;if(!q)G.vertices[i].firstarc=p;else{while(q->nextarc)q=q->nextarc;஻ᢣ┐ìíªÖ×⊤Ḅî/0q->nextarc=p;))returnOK;)intLocateVex(ALGraph&G,VertexTypev)(inti=0;while(G.vertices[i].data!=v&&i

110abcdefAflelroabcd4fgT4—^1mhabcd6fg—4Th19.9.685.15旃9.?•:20

111129.7deH]=1X1+1X2+2X3+4X4Hj=1x1+1x2+2x34-4x4a=1x2+1x34-2x4+4x52a=1xn+1x(n+1)+2x(n+2)+4x(n+3)nA8N(N+1)SN=Ean=El8N+17l=----¬----+17Nn=ln=lZ…N+l17ASL=-----+—289.9de(1)ASL=—[lxl+2x2+3x34-3x4+2x5+1x6]=3.5

112ব

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。
最近更新
更多
大家都在看
近期热门
关闭