import'dart:io';classStackX{intmaxSize;List<String>stackArray;inttop;StackX(intsize){maxSize=size;stackArray=newList<String>(maxSize);top=-1;}/// Put item on top of stackvoidpush(Stringitem){stackArray[++top]=item;}/// Take item from top of stackStringpop(){returnstackArray[top--];}/// Peek at top of stackStringpeek(){returnstackArray[top];}boolisEmpty(){returntop==-1;}intsize(){returntop+1;}StringpeekN(intn){returnstackArray[n];}/// Display Stack DatavoiddisplayStack(Strings){stdout.write(s);stdout.write('Stack (bottom -> top): ');for(inti=0;i<size();i++){stdout.write('${peekN(i)} ');}stdout.writeln();}}classInfixToPostfix{StackXstackX;Stringinput;Stringoutput='';InfixToPostfix(String_input){input=_input;intstackSize=input.length;stackX=newStackX(stackSize);}/// Do translation to postfixStringdoTranslation(){// for each charfor(inti=0;i<input.length;i++){Stringchar=input[i];// get itstackX.displayStack('For $char ');switch(char){case'+':case'-':gotOperator(char,1);break;case'*':case'/':gotOperator(char,2);break;case'(':stackX.push(char);break;case')':gotParent(char);break;default:output=output+char;break;}}while(!stackX.isEmpty()){stackX.displayStack('While ');output=output+stackX.pop();}stackX.displayStack('End ');returnoutput;}voidgotOperator(StringopThis,intpriority){while(!stackX.isEmpty()){StringopTop=stackX.pop();if(opTop=='('){stackX.push(opTop);break;}else{intprior;if(opTop=='+'||opTop=='-'){prior=1;}else{prior=2;}if(prior<priority){stackX.push(opTop);break;}else{output=output+opTop;}}}stackX.push(opThis);}voidgotParent(Stringchar){while(!stackX.isEmpty()){StringcharX=stackX.pop();if(charX=='('){break;}else{output=output+charX;}}}}voidmain(){Stringinput,output;stdout.writeln('Enter infix:');input=stdin.readLineSync();InfixToPostfixinfixToPostfix=newInfixToPostfix(input);output=infixToPostfix.doTranslation();stdout.writeln('Postfix is $output');}