Solved

Infix Expression to Prefix-Expression

Posted on 1997-11-23
4
1,513 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
  • 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SendMessage fails while PostMessage works 2 116
Template syntax for variable length arrays 9 75
Arduino EDI - Programming language 3 97
Android development question 2 38
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

825 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