By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,129 Members | 1,245 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,129 IT Pros & Developers. It's quick & easy.

prefix to infix conversion

P: n/a
Hi every one,

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

Dec 23 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Dec 23 '06 #2

P: n/a
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
..

Richard Heathfield wrote:
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.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Dec 26 '06 #3

P: n/a
NageshB wrote:
>
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/>
Dec 26 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.