New Member FAQ | Forums | Earn Revenue | Posting Guidelines | Help Topics


ResourcesPractice TestsAsk ExpertsQuestion PapersJobsStudy in UKUniversitiesCollegesCoursesSchoolsTraining


My Profile

Awards & Gifts


Active Members
TodayLast 7 Daysmore...





Conversion of infix expression to postfix expression


Posted Date:     Total Responses: 0    Posted By: pankaj agarwala   Member Level: Silver   Points/Cash: 3   


### Write a C program to Convert infix expression to postfix expression using stack



#define MAX 50
#include
#include
#include
#include
char stack[MAX],ch ;

int top=-1;
void push(char ch)
{
if(top==MAX-1)
return ;
stack[++top]=ch;
}
char pop()
{
if (top==-1)
return '\0';
else
return stack[top--];
}
int prece(char ch)
{
if(ch=='*'||ch=='/')
return 2;
else if(ch=='+'||ch=='-')
return 1;
else
return 0;
}
void main()
{
clrscr();
char in[50],post[50];
int i=0,j=0,len;
printf("\n Enter Experission in INFIX notation");
gets(in);
len=strlen(in);

in[len]=')';
in[len+1]='\0';
push('(');
while(in[i]!='\0')
{
if(isalpha(in[i]))
post[j++]=in[i];
else if(in[i]=='(')
push('(');
else if(in[i]==')')
{
while((ch=pop())!='(')
post[j++]=ch;
}
else if(in[i]!=32)
{
while(prece(ch=pop())>=prece(in[i]))
post[j++]=ch;
push(ch);
push(in[i]);
}
i++;
}
post[j]='\0';
printf("post fix notation is %s",post);
getch();
}


Project Feedbacks


No feedbacks found. Be the first to respond...

Post Feedback
You must Sign In to post a feedback.
Next Project: Java Threading or multithreading Programs
Previous Project: Evaluation of PostFix Expression

Return to Project Index

Post New Project


Related Projects

Subscribe to Email
  • Get Jobs by Email
  • Forum posts by Email
  • Articles by Email



  • website counter

    Online Membersbenson gomez
    Ashish Kumar
    Iti Tyagi
    Sakshi Sood
    dks
    Arvind
    siva
    sathishkumar
    Shiyas
    Kamlesh. M. Dhurve
    Saraswathi
    More...



    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    AdSense Revenue Sharing sites   Advertise   Talk to Tony John
    ISC Technologies, Kochi - India
    2006 - 2012 All Rights Reserved.