prefix to infix conversion

N

NageshB

Hi every one,

can any help me in converting prefix to infix using Stack in c I know
the reverse
 
R

Richard Heathfield

NageshB said:
Hi every one,

can any help me in converting prefix to infix using Stack in c I know
the reverse

The belt-and-braces technique is easy enough:

prefix_to_infix(stream, stack)
if stack is not empty
pop a node off the stack
if this node represents an operator
write an opening parenthesis to stream
prefix_to_infix(stream, stack)
write operator to stream
prefix_to_infix(stream, stack)
write a closing parenthesis to stream
else
write value to stream
endif
endif
endfunc

Removing redundant parentheses is left as an exercise.
 
N

NageshB

Thank you Richard you suggested recursive solution can it possible to
have iterative one for this.I tried a lot for iterative i m not getting
..
 
C

CBFalconer

NageshB said:
Thank you Richard you suggested recursive solution can it possible to
have iterative one for this.I tried a lot for iterative i m not getting

Please do not top-post. Your article should follow (or be
intermixed with) the material you quote, after snipping anything
irrelevant to your reply. See the following links:

--
Some informative links:
<http://www.geocities.com/nnqweb/>
<http://www.catb.org/~esr/faqs/smart-questions.html>
<http://www.caliburn.nl/topposting.html>
<http://www.netmeister.org/news/learn2quote.html>
<http://cfaj.freeshell.org/google/>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,792
Messages
2,569,639
Members
45,352
Latest member
SherriePet

Latest Threads

Top