0
   

INFIX TO POSTFIX:

 
 
Reply Thu 2 Jul, 2009 05:02 pm
i have written a program to convert infix expression to postfix expression.
There are no compilation errors but on run-time it shows the message : "Program Termination". Please help me by making me know where the error lies, here is the program:

#include<stdio.h>
#include<conio.h>
#include<string.h>

#define MAX 30
int topS=-1,topE=-1;
char stack1[MAX],stack2[MAX];
char pop()
{
if(topS==-1)
return '#';
return stack1[topS--];
}

void pushS(char s)
{
stack1[++topS]=s;
}
void pushE(char s)
{
stack2[++topE]=s;
}

void show()
{
int j;
for(j=0;j<=topE;j++)
printf("%c",stack2[j]);
}
void call()
{
while(stack1[topS]!='(')
pushE(pop());
pop();
}

void main()
{
clrscr();
char pe[MAX],len,i=0;
printf("\n Enter the Infix Expression");
gets(pe);
len=strlen(pe);
while(i<len)
{
if(pe=='(')
pushS(pe);
else if((pe>=65 && pe<=90) || (pe>=97 && pe<=122))
pushE(pe);
else if(pe==')')
call();
else
{
if(pe=='+')
{
while(stack1[topS]!='(')
pushE(pop());
pushS('+');
}
else if(pe=='-')
{
while(stack1[topS]!='(')
pushE(pop());
pushS('-');
}
else if(pe=='^')
{
pushS('^');
}
else if(pe=='*')
{
if((stack1[topS]=='+') || (stack1[topS]=='-') || (stack1[topS]=='('))
{
pushS('*');
}
else if((stack1[topS]=='^') || (stack1[topS]=='/'))
{
while((stack1[topS]!='+') || (stack1[topS]!='-') || (stack1[topS]!='('))
pushE(pop());
pushS('*');
}
}
else if(pe=='/')
{
if((stack1[topS]=='+') || (stack1[topS]=='-') || (stack1[topS]=='('))
{
pushS('/');
}
else if((stack1[topS]=='^') || (stack1[topS]=='*'))
{
while((stack1[topS]!='+') || (stack1[topS]!='-') || (stack1[topS]!='('))
pushE(pop());
pushS('/');

}
}
}
i++;
}
printf("\n The Conversion has been done");
printf("\n The resulting Postfix Expression is:\n");
show();
getch();
}

  • Topic Stats
  • Top Replies
  • Link to this Topic
Type: Question • Score: 0 • Views: 2,149 • Replies: 4
No top replies

 
Ragman
 
  -1  
Reply Thu 2 Jul, 2009 05:30 pm
@Prateekr10,
how much is it worth to you?
Prateekr10
 
  1  
Reply Thu 2 Jul, 2009 06:08 pm
@Ragman,
That means you dont know the answer......
Ragman
 
  -1  
Reply Thu 2 Jul, 2009 06:36 pm
@Prateekr10,
'ya think?

If you become a programmer, will you still ask questions here on A2K to do your work for you?
Prateekr10
 
  0  
Reply Tue 29 Dec, 2009 07:01 am
@Ragman,
and what did you do a**h***,
if you are that brilliant and genius
why are you even on this site.............
0 Replies
 
 

Related Topics

Clone of Micosoft Office - Question by Advocate
Do You Turn Off Your Computer at Night? - Discussion by Phoenix32890
The "Death" of the Computer Mouse - Discussion by Phoenix32890
Windows 10... - Discussion by Region Philbis
Surface Pro 3: What do you think? - Question by neologist
Windows 8 tips thread - Discussion by Wilso
GOOGLE CHROME - Question by Setanta
.Net and Firefox... - Discussion by gungasnake
Hacking a computer and remote access - Discussion by trying2learn
 
  1. Forums
  2. » INFIX TO POSTFIX:
Copyright © 2024 MadLab, LLC :: Terms of Service :: Privacy Policy :: Page generated in 0.06 seconds on 04/24/2024 at 07:34:05