New Member FAQ | Forums | Earn Revenue


Resources Entrance Ask Experts Exam Papers Jobs English Projects Universities Colleges Courses Schools Training My India



My Profile
Active Members
TodayLast 7 Days more...



Awards & Gifts
Online Exams

Fresher Jobs


Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian cities including Bangalore, Chennai, Hyderabad, Pune or Kochi

Resources


Find educational articles, blogs, discussion threads and other resources.

Colleges


Find details about any college in India or search for courses.

website counter



infix to postfix without parenthesis


Posted Date:     Total Responses: 0    Posted By: PRITESH   Member Level: Bronze   Points/Cash: 3   


#include
#include
#include
#include
#include

int f(char);
int r(char);
void push(char);
char pop(void);

char s[20];
int top=-1;

void main()
{
int rank=0,i=0,j=0;
char next,c,infix[20],polish[20],temp;
clrscr();

gets(infix);
push('#');
strcpy(polish,NULL);
next=infix[i];

while(next!='#')
{
while(f(next)<=f(s[top]))
{
temp=pop();
polish[j]=temp;
j++;
rank=rank+r(temp);
if(rank<1)
{
printf(" I N V A L I D ");
getch();
exit(0);
}
}
push(next);
i++;
next=infix[i];
}
while(s[top]!='#')
{
temp=pop();
polish[j]=temp;
j++;
rank=rank+r(temp);
if(rank<1)
{
printf(" I N V A L I D ");
getch();
exit(0);
}
}
if(rank==1)
{
printf(" V A L I D ");
puts(polish);
//getch();
}
else
{
printf("I N V A L I D");
exit(0);
getch();
}
getch();
}

// 4 f

int f(char c)
{
if(c=='+'|| c=='-')
return (1);
else if(c=='*'|| c=='/')
return (2);
else if(isalpha(c))
return (3);
else if(c=='#')
return (0);
}


// 4 rank

int r(char c)
{
if(c=='+'||c=='-'||c=='*'||c=='/')
return (-1);
else
return (1);
}

// 4 push

void push(char c)
{

top=top+1;
s[top]=c;
return(s[top]);
}

// 4 pop
char pop(void)
{
top=top-1;
return(s[top+1]);
}
























Project Feedbacks

Author: m v lathkarMember Level: GoldRevenue Score: 4 out of 54 out of 54 out of 54 out of 5
The program uses an array s[20] as stack with top as push / pop point. However, the push / pop operation should be implemented by declaring

struct stack
{
char s[20]; int top;
};

so that any direct manipulation of s[20] is avoided and the array as well as top element are accessed throuh struct stack variable


Post Feedback
You must Sign In to post a feedback.
Next Project: BOILER EFFICIENCY
Previous Project: GENERAL WORKING OF A THERMAL POWER STATION

Return to Project Index

Post New Project


Related Projects



Advertise Here





Contact Us   Advertise   Editors    Privacy Policy    Terms Of Use   

ISC Technologies.
2006 - 2009 All Rights Reserved.