123 Eng

Engineering the engineers™


Latest Jobs   Forum Map

 


Home
Source Codes
Engineering Colleges

Training  Reports
Seminar Reports
Placement Papers

Forums

   Computer Science / IT
   Electronics
   Electrical
   Mechanical
   Chemical
   Civil

   CAT / MBA

   GMAT / Foreign MBA
Latest Jobs

Engineering Jobs / Technical Jobs
Management Jobs

Sitemap
Terms of use

Displaying  Source Code(s)  
 

 
--------------------------------------------------------------------------------

infix _to_ postfix_conversion

--------------------------------------------------------------------------------

Description : Not Specified

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<ctype.h>
#define N 100

void push(char *stk,int *sp,char item);
char pop(char *stk,int *sp);


void main()
{
static char stack[N],target[N];
char *t,*s,n1,n2,item,str[N];
int p1,p2,i,top=-1;
clrscr();
printf("
Enter the infix notation :");
gets(str);
s=str;
t=target;
while(*s)
{
if(*s==' ' || *s==' ')
{
s++;
continue;
}
if(isdigit(*s) || isalpha(*s))
{
while(isdigit(*s) || isalpha(*s))
{
*t=*s;
t++;
s++;
}
}

if(*s=='(')
{
push(stack,&top,*s);
s++;
}

if(*s==')')
{
n1=pop(stack,&top);
while(n1!='(')
{
// n1=pop(stack,&top);
*t=n1;
t++;
n1=pop(stack,&top);
}
s++;
}
if(*s=='+'||*s=='*'||*s=='/'||*s=='%'||*s=='-')
{
if(top==-1)
{
push(stack,&top,*s);
}
else
{
n1=pop(stack,&top);
while(priority(n1)>=priority(*s))
{
*t=n1;
t++;
n1=pop(stack,&top);
}
push(stack,&top,n1);
push(stack,&top,*s);
}
s++;
}
}


while(top!= -1)
{
n1=pop(stack,&top);
*t=n1;
t++;
}

t='
 

 

 

Contribute content or training reports / feedback / Comments
job placement papers
All rights reserved © copyright 123ENG