Solved

Infix Expression to Prefix-Expression

Posted on 1997-11-23
4
1,505 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
Comment Utility
Could you be a little clearer?  Defining what you mean by infix and prefix would be helpful.  Thanks!
0
 

Author Comment

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

Accepted Solution

by:
mitchell042997 earned 70 total points
Comment Utility
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
Comment Utility
Thanks a lot.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now