Infix Expression to Prefix-Expression

I want a C++ code which convert an infix-expression (String1) into a pre-fix-expression (String2).
matchzAsked:
Who is Participating?
 
mitchell042997Connect With a Mentor Commented:
Basically, what you're going to want to do is create an expression tree.  So, in your example above, your tree would look like:

    +
   / \
  c   *
     / \
    a   b

Then, if you did a preorder traversal, it would return +c*ab, an inorder traversal would return c+a*b and a postorder traversal would return cab*+.

I am assuming you've have some knowledge about trees.  If this in incorrect, let me know, and I can provide source code and further examples.
0
 
mitchell042997Commented:
Could you be a little clearer?  Defining what you mean by infix and prefix would be helpful.  Thanks!
0
 
matchzAuthor Commented:
Sorry, That's:
Infix Expression : a * b + c
=> Prefix Expression : + c * a b
0
 
matchzAuthor Commented:
Thanks a lot.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.