Solved

Infix Expression to Prefix-Expression

Posted on 1997-11-23
4
1,524 Views
Last Modified: 2008-03-06
I want a C++ code which convert an infix-expression (String1) into a pre-fix-expression (String2).
0
Comment
Question by:matchz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 2

Expert Comment

by:mitchell042997
ID: 1173984
Could you be a little clearer?  Defining what you mean by infix and prefix would be helpful.  Thanks!
0
 

Author Comment

by:matchz
ID: 1173985
Sorry, That's:
Infix Expression : a * b + c
=> Prefix Expression : + c * a b
0
 
LVL 2

Accepted Solution

by:
mitchell042997 earned 70 total points
ID: 1173986
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
 

Author Comment

by:matchz
ID: 1173987
Thanks a lot.
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question