?
Solved

having problems with parenthesis in postfix to infix conversion

Posted on 2003-02-21
1
Medium Priority
?
378 Views
Last Modified: 2007-12-19
hi, this is my first time but i really need help.

The program i'm writing is a postfix to infix converter in c++, the conversion part concerning the placement of operators is working fine (i'm using a stack) and didn't take much time but i'm having problems dealing with the parenthesis, in part because i'm trying to avoid useless ones. For example: (a*b)+(c*d)=a*b+c*d. If someone has an idea to solve my problem or who can tell me what propreties have () regarding operators in postfix notation, please let me know.
Thank you.
0
Comment
Question by:rocketsbay
[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
1 Comment
 
LVL 16

Accepted Solution

by:
imladris earned 400 total points
ID: 7994016
The way the operator stack normally works for that algorithm, is to have weaker bindings flush stronger bindings from the stack, right?
So, for example, if a + is stashed in the stack, and then a * comes along you keep going.
On the other hand, if a * is in the operator stack and then you find a +, the + causes the * to be flushed to the output stream, before the * is put on the stack.

In keeping with that, the left paren should be the weakest "binding" or priority. This means it will stay in the stack when "stronger" operators come along.

Then, when you get the right paren, flush all the operators in the stack, until you hit the left paren, and pop that off as well.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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 shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
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.
Suggested Courses
Course of the Month13 days, 11 hours left to enroll

801 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