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/Embed
Type: Question • Score: 0 • Views: 140 • Replies: 3

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

If you become a programmer, will you still ask questions here on A2K to do your work for you?
0 Replies
 
 

Related Topics

The "Death" of the Computer Mouse - Discussion by Phoenix32890
Blue screen of Death - Question by dagmaraka
How does one uninstall a program? - Question by Woollcott
how do you type pi? - Question by C99
Conficker worm - Discussion by msolga
SYSTRAY MISSING - Discussion by Misti26
Broad Jump Client Foundation - Discussion by Mustang
 
  1. able2know
  2. » INFIX TO POSTFIX:
Copyright © 2009 Horizontal Verticals :: Page generated in 0.33 seconds on 11/28/2009 at 01:10:14 Top End