473,236 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,236 software developers and data experts.

Infix to Postfix conversion

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:

Expand|Select|Wrap|Line Numbers
  1. #include<iostream.h>
  2. #include<conio.h>
  3. #include<stdio.h>
  4. #include<ctype.h>
  5. #include<string.h>
  6. #include<process.h>
  7. const int max=100;
  8. struct stack
  9. { char a[max];
  10.   int top;
  11. }s;
  12.  
  13. void push(char c)
  14. { if(s.top==max)
  15.    cout<<"\n Overflow";
  16.   else
  17.    { s.a[s.top]=c;
  18.      s.top++;
  19.    }
  20. }
  21.  
  22. char pop()
  23. { char x='#';
  24.   if(s.top==0)
  25.    cout<<"\n Underflow";
  26.   else
  27.    { s.top--;
  28.      x=s.a[s.top];
  29.    }
  30.    return(x);
  31. }
  32. void main()
  33. { clrscr();
  34.   stack s;
  35.   s.top=0;
  36.   char in[100],out[100];
  37.   char c;
  38.   int ch,n;
  39.   cout<<"\n Enter the infix expression:";
  40.   gets(in);
  41.  
  42.   n=strlen(in);
  43.  
  44.   for(int i=0;i<n;i++)
  45.   { if(isalpha(in[i]))
  46.      out[i]=in[i];
  47.  
  48.     if(in[i]=='+'||in[i]=='-')
  49.      { if(s.a[s.top]=='^'||s.a[s.top]=='*'||s.a[s.top]=='/'||s.a[s.top]=='+'||s.a[s.top]=='-')
  50.      { c=pop();
  51.        if(c!='#')
  52.        {    out[i]=c;
  53.           push(in[i]);
  54.        }
  55.  
  56.      }
  57.  
  58.     else
  59.      push(in[i]);
  60.      }
  61.     if(in[i]=='*'||in[i]=='/')
  62.        { if(s.a[s.top]=='^'||s.a[s.top]=='*'||s.a[s.top]=='/')
  63.      { c=pop();
  64.        if(c!='#')
  65.        {
  66.        out[i]=c;
  67.        push(in[i]);
  68.        }
  69.      }
  70.  
  71.      else
  72.       push(in[i]);
  73.        }
  74.     if(in[i]=='^')
  75.        { if(s.a[s.top]=='^')
  76.      { c=pop();
  77.        if(c!='#')
  78.        {
  79.        out[i]=c;
  80.        push(in[i]);
  81.        }
  82.      }
  83.      else
  84.       push(in[i]);
  85.        }
  86.     if(in[i]=='(')
  87.      push(in[i]);
  88.     if(in[i]==')')
  89.     { while(s.a[s.top]!='(')
  90.       { c=pop();
  91.     if(c!='#')
  92.     out[i]=c;
  93.       }
  94.       pop();
  95.     }
  96.  }
  97.  while(s.top!=0)
  98. {  c=pop();
  99.    if(c!='#')
  100.     out[i]=c;
  101. }
  102.  cout<<"\n The postfix expression is \n";
  103.  
  104.   puts(out);
  105.  getch();
  106. }
Oct 2 '07 #1
0 2485

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

Similar topics

5
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...
22
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
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>...
11
by: Nhd | last post by:
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
5
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...
30
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”....
4
by: madhumitha29 | last post by:
Does anyone know a simple C program to covert an infix to a postfix expression?plz kindly help!
1
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...
2
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.