Help pplz. . convert infix to postfix. .

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2007
Posts: 7
Reputation: Madzts is an unknown quantity at this point 
Solved Threads: 1
Madzts Madzts is offline Offline
Newbie Poster

Help pplz. . convert infix to postfix. .

 
0
  #1
May 9th, 2007
Hi. . can any one help me in converting infix to postfix. . i do not know what is wrong in my code. . help!!!plz
  1. #include<iostream>
  2. #include<string>
  3. #include<conio.h>
  4. #include<stdio.h>
  5. using namespace std;
  6. void main()
  7. {
  8. char stack[10];
  9. char input[10];
  10. char output[10];
  11. char plusminus,multdiv;
  12. int a;
  13. cout<<"\tInput an infix expression:";
  14. gets(input);
  15. int i;
  16. i=strlen(input);
  17. cout<<strlen(input);
  18. for(a=0;a<=i;a++){
  19. if(input[a]>='a'&&input[a]<='z'){
  20.  
  21. output[a]=input[a];
  22. }
  23. else if(input[a]=='+'||input[a]=='-'){
  24. plusminus=input[a];
  25. }
  26. else if(input[a]=='*'||input[a]=='/'){
  27. multdiv=input[a];
  28. }
  29. if(input[a]==plusminus){
  30. stack[a]=input[a];
  31. if(stack[a]==plusminus&&stack[a+1]==plusminus){
  32. output[a]=stack[a];
  33. }
  34. }
  35. else if(input[a]==multdiv){
  36. stack[a]=input[a];
  37. if(stack[a]==multdiv&&stack[a+1]==multdiv){
  38. output[a]=stack[a];
  39. }
  40. }
  41. }
  42. cout<<"\tPostfix Expression :"<<output<<"\n";
  43. }
Last edited by Narue; May 9th, 2007 at 10:05 am. Reason: Added code tags
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 275
Reputation: andor has a spectacular aura about andor has a spectacular aura about andor has a spectacular aura about 
Solved Threads: 29
andor's Avatar
andor andor is offline Offline
Posting Whiz in Training

Re: Help pplz. . convert infix to postfix. .

 
1
  #2
May 9th, 2007
First of all add code tags. Find out why void main and gets are bad. There is many posts about them.
Last edited by andor; May 9th, 2007 at 9:02 am. Reason: Corecting "add code tags" to "First of all add code tags"
If you want to win, you must not loose (Alan Ford)
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Help pplz. . convert infix to postfix. .

 
0
  #3
May 9th, 2007
Yes void main, gets (you're using c++ so no need for them anyway) conio.h all wrong and/or unnecessary.

http://www.daniweb.com/code/snippet599.html

See there for ideas.
Last edited by iamthwee; May 9th, 2007 at 2:27 pm.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: Help pplz. . convert infix to postfix. .

 
0
  #4
May 10th, 2007
Originally Posted by Madzts View Post
Hi. . can any one help me in converting infix to postfix. . i do not know what is wrong in my code. . help!!!plz
Neither do we, you didn't tell us what it's doing wrong, nor what it does right. We need information to understand the problem.

And check the following links to see what is wrong with gets() and void main()
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 2
Reputation: Afaq Haider is an unknown quantity at this point 
Solved Threads: 0
Afaq Haider Afaq Haider is offline Offline
Newbie Poster

Conversion of infix expression to postfix using stacks (simple C++ Program)

 
-1
  #5
Oct 19th, 2009
Friends plz help me to write simple c++ program just to convert infix expression to postfix expression using stacks, i don't know abt C++ too much, just write a simple c++ program, i have to submit my assignment, mail me at: SNIP
Last edited by happygeek; Oct 19th, 2009 at 6:42 pm. Reason: email snipped
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC