954,487 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Help pplz. . convert infix to postfix. .

Hi. . can any one help me in converting infix to postfix. . i do not know what is wrong in my code. . help!!!plz

#include<iostream>
#include<string>
#include<conio.h>
#include<stdio.h>
using namespace std;
void main()
{
 char stack[10];
 char input[10];
 char output[10];
 char plusminus,multdiv;
 int a;
 cout<<"\tInput an infix expression:";
 gets(input);
int i;
i=strlen(input);
cout<<strlen(input);
for(a=0;a<=i;a++){
  if(input[a]>='a'&&input[a]<='z'){
   
   output[a]=input[a];
  }
  else if(input[a]=='+'||input[a]=='-'){
   plusminus=input[a];
  }
  else if(input[a]=='*'||input[a]=='/'){
   multdiv=input[a];
  }
  if(input[a]==plusminus){
   stack[a]=input[a];
   if(stack[a]==plusminus&&stack[a+1]==plusminus){
    output[a]=stack[a];
   }
  }
  else if(input[a]==multdiv){
   stack[a]=input[a];
   if(stack[a]==multdiv&&stack[a+1]==multdiv){
    output[a]=stack[a];
   }
  } 
 }
  cout<<"\tPostfix Expression :"<<output<<"\n"; 
}
Madzts
Newbie Poster
7 posts since Apr 2007
Reputation Points: 10
Solved Threads: 1
 

First of all add code tags. Find out why void main and gets are bad. There is many posts about them.

andor
Posting Whiz in Training
276 posts since Jun 2005
Reputation Points: 251
Solved Threads: 29
 

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.

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 
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()

WaltP
Posting Sage w/ dash of thyme
Moderator
10,505 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

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

Afaq Haider
Newbie Poster
2 posts since Oct 2009
Reputation Points: 9
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You