Top baner Big

Your Ad Here

Top Banner

Your Ad Here

Saturday, November 22, 2008

expression tree and perform the expression

/*Program : expression tree and perform the expression
Programmer ::fizmhd(MEA) www.mdown.co.cc*/

#include

void check(char);
void push(char);

struct node
{
char info;
struct node *r,*l;
}temp,*operator[10],*operand[10];

typedef struct node N;


int p,top1=0,top2=0;

main()
{
char exp[20];
printf("\nENter the expression :: ");
gets(exp);
for(i=0;exp[i]!='\0';i++)
{
check(exp[i]);
printf("\nThe priority value of %c is %d \n",exp[i],p);
push(exp[i]);
}

}



void check(char x)
{
p=-1;
switch(x)
{
case '*' :
p=1;
break;
case '/' :
p=1;
break;
case '+' :
p=2;
break;
case '-' :
p=2;
break;
default :
p=3;
break;

}
}

void push(char x)
{
temp=(N*)malloc(sizeof(N));
temp->info=x;
temp->l=NULL;
temp->r=NULL;
switch(p)
{
case 1 :
break;
case 2 :
break;
case 3 :
operand[top1++]=temp;
break;
}
}

No comments:

Easy Hits

EasyHits4U.com - Your Free Traffic Exchange - 1:1 Exchange Ratio, 5-Tier Referral Program. FREE Advertising!

Bottom Square