Postfix to Infix | C # program to find infix for a given postfix . ; Get Infix for a given postfix expression ; Push operands ; We assume that input is a valid postfix and expect an operator . ; There must be a single element in stack now which is the required infix . ; Driver code
using System ; using System . Collections ; class GFG { static Boolean isOperand ( char x ) { return ( x >= ' a ' && x <= ' z ' ) || ( x >= ' A ' && x <= ' Z ' ) ; } static String getInfix ( String exp ) { Stack s = new Stack ( ) ; for ( int i = 0 ; i < exp . Length ; i ++ ) { if ( isOperand ( exp [ i ] ) ) { s . Push ( exp [ i ] + " " ) ; } else { String op1 = ( String ) s . Peek ( ) ; s . Pop ( ) ; String op2 = ( String ) s . Peek ( ) ; s . Pop ( ) ; s . Push ( " ( " + op2 + exp [ i ] + op1 + " ) " ) ; } } return ( String ) s . Peek ( ) ; } public static void Main ( String [ ] args ) { String exp = " ab * c + " ; Console . WriteLine ( getInfix ( exp ) ) ; } }