stack - Why do we have to reverse the string when converting from infix to prefix -
in first step of converting infix prefix can explain in simple terms why should reverse string? there alternative method convert?
yes, absolutely right if have convert infix prefix have scan string right left.
why not left right?
if scan left right require future knowledge of operators in string.
example 1 :
infix : 2+3 prefix : +23
now, when convert left right should have knowledge of + yet appear in string. looks simple in particular example, consider example given below.
example 2:
infix : 2+3*4/5-6*7 prefix : -+2/*345*67
now, if scan left right when scan 0th index of string program should have knowledge of - going appear in 7th index of string hectic job.
so safest way scan string right left.
Comments
Post a Comment