We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Infix Expression to Prefix-Expression

matchz
matchz asked
on
Medium Priority
1,554 Views
Last Modified: 2008-03-06
I want a C++ code which convert an infix-expression (String1) into a pre-fix-expression (String2).
Comment
Watch Question

Could you be a little clearer?  Defining what you mean by infix and prefix would be helpful.  Thanks!

Author

Commented:
Sorry, That's:
Infix Expression : a * b + c
=> Prefix Expression : + c * a b
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.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Thanks a lot.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.