您好,欢迎访问三七文档
2005.9.4TemplatezzC++intmin(inta,intb){returnab?a:b;}doublemin(doublea,doubleb){returnab?a:b;}“min()”TemplateclassTypeTypemin(Typea,Typeb){returnab?a:b;}zztemplatetypenameT1,typenameT2classpair{public:T1first;T2second;pair(T1x,T2y):first(x),second(y){}};STLvectorsortSTL#includealgorithm#includefunctional#includevector#includeiostreamusingnamespacestd;intmain(){intia[6]={27,210,12,47,109,83};vectorint,allocatorintvec(ia,ia+6);coutcount_if(vec.begin(),vec.end(),not1(bind2nd(less_equalint(),40)));return0;}//result:483109471221027vec.begin()vec.end()STLSequenceContainersAssociativeContainersContainersvectordequelistset,multisetmap,multimapSTLstackqueuepriority_queueSTLzzzzz—STLC++,D.R.Musser,G.J.Derge,A.Saini.zC++,H.M.Deitel,P.J.Deitel.zC++,BjarneStroustrup.zSTL,.//SGISTLzErichGamma.z(FareySeries)nn0/11/1nFnF80/1,1/8,1/7,1/6,1/5,1/4,2/7,1/3,3/8,2/5,3/7,1/2,4/7,3/5,5/8,2/3,5/7,3/4,4/5,5/6,6/7,7/8,1/1znFnnFnSTLSTLzzmodz(x^5+2*x^4+x^3)+(4*x^3)=x^5+2*x^4+5*x^3z(x^5+2*x^4+x^3)-(4*x^3)=x^5+2*x^4-3*x^3z(x+1)*(x+1)=x^2+2*x+1z(x^2+2*x+2)/(x+1)=x+1zmod(x^2+2*x+2)(x+1)=1z1.2.mod3.x4.xvector1.2.3.STLvectorvectorvectorcharv1,v2;vectorchar::iteratori;for(i=v1.begin();i!=v1.end();i++){v2.push_back(*i);//}for(i=v1.begin();i!=v1.end();i++){v2.insert(v2.begin(),*i);//}vectorvectorcharvector1;while(vector1.size()0){vector1.pop_back();//}j=find(vector1.begin(),vector1.end(),’m’);vector1.erase(j--);//vectorzvectorC++54871[0][1][2][3][4]elementmax_size-1size=51.vectorvector2.vector3.vectorvectorintv;voiddoSomething(constint*pInts,size_tnumInts);doSomething(&v[0],v.size());vectordequezz(vector)zdequevectordequefor(i=deque1.begin();i!=deque1.end();i++){deque2.push_front(*i);//}deque2.pop_front();//dequedequevectordequedequelistzzzN1234LeftEndRightEnd1.2.3.zset/multisetsetsetmultisetzmap/multimapmapsetmapkey/valuekeykey——zvs.1234512345stackzzztopPUSHtopPOPstackzstack54871[0][1][2][3][4]elementmax_size-1size=5N1234LeftEndRightEndstackstackTTdequestackT,vectorTTvectorstackT,listTTliststackT,dequeTTdequequeuezzz[0][1][2][3][4]queuezqueueABCDfrontrearrearfrontBCDrearfrontqueuequeueTTdequequeueT,listTTlistqueueT,dequeTTdequevectorqueuezqueuevectorvectorpop_frontzvectorpop_frontzzSTLz——25139874251398742513987425139874STLquick_sort——zmnfi(x)ximax{f1(x1)+f2(x2)+…+fn(xn)}x1+x2+…+xn=m,xiNz54∈zFk(x)xkzzppxk-1xkzz)}()({max)(10kkkkxxkxxFxfxFk−+=−≤≤)()(11xfxF=•54321F4(x)x4(x)F3(x)x3(x)F2(x)x2(x)F1(x)x1(x)x24402015523321514422301013321105122202011100000f4(x)f3(x)f2(x)f1(x)x111122133144155110120162213264110131303413434201311331501611zzztzT=||×tzz4z123495427131234342423434232292328282829n-1zzAABBzzzzznwjvjj=1,2,…,niixi0xi1czc0,wi0,vi0,i=1,…,nzx1,x2,…,xn∑=niiixv1max∑=≤niiicxw1nixi,...,2,110=≤≤zz1234566555164362G=(V,E)N=(V,E,W)T=(V,E’)NW(T)TNNEe∈)(eω∑∈=')()(EeeTWωzPrimzPrim12345665551643621234563164422553zKruscalzKruskal123456655516436212345612345
本文标题:经典数据结构与算法
链接地址:https://www.777doc.com/doc-6430847 .html