473,889 Members | 2,031 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

conversion from infix to postfix

24 New Member
Hi... I need a program to convert an infix arithmetic expression to postfix with the use of stacks... Can anyone tell me how do i go about implementing this? thanks
Sep 17 '06
11 48772
Banfa
9,065 Recognized Expert Moderator Expert
None of this code

Expand|Select|Wrap|Line Numbers
  1.       //Conversion from Infix to Postfix expression
  2.       vector<char> postFix;
  3.       for (vector<char>::const_iterator ptr = v.begin(); ptr !=v.end(); ++ptr)
  4.       {
  5.         switch(ch)
  6.         {
  7.                   case operand: 
  8.                        postfixExp = postfixExp + ch;
  9.                        break;
  10.                   case '(': 
  11.                        Stack.push (ch);
  12.                        Break;
  13.                   case ')':
  14.                        while (stack.top()!='(')
  15.                        {
  16.                              postfixExp = postfixExp + stack.top();
  17.                              Stack.pop();
  18.                        } //end while
  19.  
  20.                        Stack.pop();
  21.                        break;
  22.  
  23.                   //infix to postfix - use stack for storing operators
  24.                   case operator:
  25.  
  26.                        while (!Stack.isEmpty() && Stack.top != '(' && precedence(ch) >= precedence(stack.top()))
  27.                        {
  28.                              postfixExp = postfixExp + Stack.top();
  29.                              Stack.pop();
  30.                         } end while
  31.              }//end switch
  32.  
  33.     } //end for
  34.  
  35.     while (!Stack.isEmpty())
  36.     {
  37.           postfixExp = postfixExp + Stack.top();
  38.           Stack.pop()
  39.     }// end while
  40.  
Is inside a function and is causing a syntax error

It doesn't appear to have any purpose so I guess you can just delete it as the program compiles fine without it.
Sep 20 '06 #11
Nhd
24 New Member
hi Banfa.. my purpose in typing out those codes is to convert infix to postfix..

for example:
Sample input 1
1 + 2 * 3 - 4 / 2 + 5 * 6
Sample output 1
35

Sample input 2
( 10 + 20 ) * 30 - 4000 / 20 + 50 * 60
Sample output 2
3700

I'm trying to write a program for this... and my notes shows only these codes, the one that i type out...

what should i do now... :(
Sep 20 '06 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

5
5992
by: KidLogik | last post by:
Hello! I am converting an infix expression string into a postfix so that I will be able to evaluate it easier -> (5*(((9+8)*(4*6))+7)) == 598+46**7+* I believe the rule is "Replace all occurances of two operands followed by an operator by their infix equivalent"
22
3812
by: Tony Johansson | last post by:
Hello Experts! I'm reading i a book about C++ and they mention infix with telling what it is. I hope you out there can do so. Many thanks! //Tony
19
11318
by: caramel | last post by:
i've been working on this program forever! now i'm stuck and going insane because i keep getting a syntax error msg and i just can't see what the compiler is signaling to! #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h>
5
3764
by: Thumbski | last post by:
Alright basically I just have one simple question. I can code perfectly fine and don't have any problems with the .cpp of the infix class but with my header I can't get anything to work really, any guideline as to how to start this would be great. It has to work with assign.cpp which is like this: int main() { Infix infix; while (true) { //cout << "Enter an infix expression like 2*(3+4): " << endl;
30
5516
by: Xah Lee | last post by:
The Concepts and Confusions of Prefix, Infix, Postfix and Fully Functional Notations Xah Lee, 2006-03-15 In LISP languages, they use a notation like “(+ 1 2)” to mean “1+2”. Likewise, they write “(if test this that)” to mean “if (test) {this} else {that}”. LISP codes are all of the form “(a b c ...)”, where the
0
2530
by: coolguyjas07 | last post by:
plzzzzzz help me out to run my source code ......... i hav written dis code to convert infix expression to postfix but not getting desired output.... plzzz help me to get correct output.. d source code is given below: #include<iostream.h> #include<conio.h> #include<stdio.h> #include<ctype.h> #include<string.h> #include<process.h>
4
3847
by: madhumitha29 | last post by:
Does anyone know a simple C program to covert an infix to a postfix expression?plz kindly help!
1
6549
by: aitia | last post by:
this the code. i used ECLIPSE to run this.. it has some codes smells that i can't seem to figure out.. can any one help? import java.io.*; import java.util.*; public class Postfix { private static Stack operators = new Stack(); private static Stack operands = new Stack();
2
5628
by: zeroeight | last post by:
Hi guys, I'm a newbie here, I just want to seek for help regarding my program. I want to implement an infix to postfix conversion only accepting numbers. Right now, I already debugged the errors and encountering loop everytime I execute it. Here's my sample code: ******************************************************************** #include<stdio.h> #include<conio.h>
0
9970
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9810
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11207
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10794
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10443
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8000
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5830
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6031
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3259
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.