您好,欢迎访问三七文档
当前位置:首页 > 临时分类 > 一个将中缀表达式转换为前缀表达式的算法
22320055JournalofHuBeiTVUniversityVol.22.No.3May.2005,124~126(,214021),,,C+;[]Tp316A[20087427(2005)030124031.,,,,,,,,2.:,,,,(AB)*DE/(F+AD)C,,(:((((AB*)(E/(F(A*D)))){}{@51,52:,,,,,,,,,@,,(,,)51,flag,flago;flag1,R;D,,;,R,,flago;,,RD,flagO;,R,R,flag;R,RD,R[20050515,,3:125,R,flag;RD,D52,52@.0,523.PrecedenceintPreeedenee(eharoP){switeh(op){cas+:eas:returnl;eas:eas/:returnZ;eas):case@:default:returno;}}Changes1,52voidChange(ehar51,ehar52){StaekR;StaekD;Initstaek(R,SM);Initstaek(D,SM);Push(R,@);inti,flag0;ehareh;istrlen(51)2;while(i=O){eh~51i;if(eh==)i;elseif(eh==)){Push(R,eh);flag0;1;}elseif(eh==(){while(Peek(R)!=)){Push(D,);Push(D,Pop(R));}PoP(R);flag=0;1;}elseif(h~+}}hh-,!}eh=~,){eharw=Peek(R);while(Preeedenee(eh)Preeedenee(w)){Push(D,):Push(D,w);PoP(R);w=Peek(R);}Push(R,eh);flag~0;l;}elseif(isdigit(cheh~.)(if(flag==0)Push(D,);Push(D,eh);flag~1;l;}}while(Peek(R)!@){Push(D,);Push(D,Pop(R));}i~0;while(!StaekEmpty(D))52i++=Pop(D);52i++@;52[i++\o;12634.,,,RRDDO(n),n,RD,O(n)5.,,,1].M.:,2001.[2.M.:,2001.(:)AAlgorithmtoConvertInfixExPressionsintoPrefixExPressionsHUYunAbstraet:Asit15omparativelydiffieulttouseomputerstoiudgetheoperationorderofoperationsym-bolsininfixexpressions,theeommonmethod15toeonvertinfixexpressionsintoprefixonesorsuffixones.Thisartielefoeusesonthealgorithmtoeonvertinfixexpressionsintoprefixones,usingC++language.Keywords:prefixexpressionsinfixexpression,,2005,,,CNKI,,:1.60002035,2.:,3.,:82Eail:hubddxb@sina.eom;xbbib@hubtvu.edu.en:430073:(027)87493807200555
本文标题:一个将中缀表达式转换为前缀表达式的算法
链接地址:https://www.777doc.com/doc-8691688 .html