[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1535
  • Last Modified:

Infix Expression to Prefix-Expression

I want a C++ code which convert an infix-expression (String1) into a pre-fix-expression (String2).
0
matchz
Asked:
matchz
  • 2
  • 2
1 Solution
 
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
 
mitchell042997Commented:
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
 
matchzAuthor Commented:
Thanks a lot.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now