C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 9th, 2003, 02:35 PM
mam1713 mam1713 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Mexico
Posts: 2 mam1713 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Infix to Prefix

Hi

I need help to convert infix formula to prefix.. Has some body an implemented C or C++ code for that..It will be great favor ...
bye..

M.A.Malik

Reply With Quote
  #2  
Old June 9th, 2003, 02:58 PM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 4,503 dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 12 h 57 m 35 sec
Reputation Power: 1165
Why to prefix notation? I'm just curious what kind of application would need that.

Many years ago (24), I did do a program that implemented the "shunting algorithm" which converts infix to postfix (AKA "reverse Polish"). Though that was written in PL/I and the only copy of it that I have is a printout buried away somewhere.

Basically, the shunting algorithm (infix to postfix) works like this (I'm writing this from memory, BTW, so I apologize in advance for any mistakes):
1. You create a stack and an output string.
2. Then you read the infix string one token at a time; each token is either an identifier or an operator:
a. If the token is an identifier (eg, a variable or a constant), then you append it onto the end of the output string.
b. If the token is an operator, then you compare its precedence with the precedence of the operator on the top of the stack.
i. If the operator on the top of stack has lower precedence, then push the new operator onto the stack.
ii. Else, pop the operator from the top of stack and append it to the output string. Then push the new operator onto the stack.
otherwise
c. If the token is an open parenthesis, then push it onto the stack.
d. If the token is a close parenthesis, then pop and append the operators from the stack until the open parenthesis is popped. Discard both parentheses.

Google for "shunting algorithm" for a more detailed and better better description. You might also find reference to an algorithm for converting infix to prefix.

Reply With Quote
  #3  
Old June 9th, 2003, 05:37 PM
mam1713 mam1713 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Mexico
Posts: 2 mam1713 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Infix, prefix or postfix

I think prefix or postfix can be more precisely used when one has to decide whether a formula is well formed or not . Formula I mean that carries all type of operators like +, -, /, *, binary or unary operator, exponent, logical operators, trignometeric functions, log functions, integrals and derivatives, quatitative operators, etc etc..
When we decide that a formula is well formed or not then we can decide about its complexity by having a binary tree. The parent of each subtree represents operators and sons are the operands...

I could not yet find an algorithm to convert infix form to prefix o postfix...

Anyone, who can help me in this matter...

M.A.Malik

Reply With Quote
  #4  
Old June 9th, 2003, 06:41 PM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 4,503 dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 3rd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 12 h 57 m 35 sec
Reputation Power: 1165
Re: Infix, prefix or postfix

Quote:
Originally posted by mam1713
I could not yet find an algorithm to convert infix form to prefix o postfix...

Dijkstra's shunting algorithm should do the job. Use a search engine to find pages that describe it. You might even find some source code.

Reply With Quote
  #5  
Old April 29th, 2008, 03:14 AM
devshed devshed is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Posts: 1 devshed User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 53 m 53 sec
Reputation Power: 0
Algorithm for Infix to postfix

Hi,
Here is the algorithm to convert infix to postfix

looker=0
loop(looker <= length of string)
token = formula[looker]
if(token is left parenthesis)
pushstack(token)
else if(token is right parenthesis)
popstack(token)
loop( not left parenthesis)
concatenate token to postfix string
popstack(token)
else if (operator)
toptoken(tokenout)
loop(not emptystack() and priority(token)<= priority(tokenout))
popstack(token1)
concatenate token1 to postfix string
pushstack(token)

else(operand)
concatenate token to postfix string

loop(not emptystack())
popstack(token)
concatenate token to postfix string



HOPE YOU GET THIS PROBLEM SOLVED!

----------------------------------------------------------------
Quote:
Originally Posted by mam1713
I think prefix or postfix can be more precisely used when one has to decide whether a formula is well formed or not . Formula I mean that carries all type of operators like +, -, /, *, binary or unary operator, exponent, logical operators, trignometeric functions, log functions, integrals and derivatives, quatitative operators, etc etc..
When we decide that a formula is well formed or not then we can decide about its complexity by having a binary tree. The parent of each subtree represents operators and sons are the operands...

I could not yet find an algorithm to convert infix form to prefix o postfix...

Anyone, who can help me in this matter...

M.A.Malik
Comments on this post
dwise1_aol disagrees: Dude, you're five years too late. And from the OP's post count, he's not been back since
then.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Infix to Prefix


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 8 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek