//To convert postfix expression into an expression tree
#include"stdio.h"
#include"conio.h"
#include"process.h"
#include"string.h"
#include"stdlib.h"
struct node{
char item;
struct node *lnode;
struct node *rnode;
}*stc[30],*temp,*root;
typedef struct node *NODEPTR;
char expression[50];
char c;
int top=0;
NODEPTR pop();
void push(NODEPTR);
void getinput();
void inorder(NODEPTR p);
int main (){
getinput();
int i,j;
for(i=0;i<strlen(expression);i++)
{
printf("\nstrlength=%d--------for i=%d\n",strlen(expression),i);
c=expression[i];
switch(c)
{
case '+':
case '-':
case '*':
case '/':
case '^':
{ temp=(NODEPTR)malloc(sizeof(struct node));
temp->item=c;
temp->rnode=pop();
temp->lnode=pop();
push(root);
}
default :
{ temp=(NODEPTR)malloc(sizeof(struct node));
temp->item=c;
temp->lnode=NULL;
temp->rnode=NULL;
push(temp);
} void free(void *ptr);
break;
}
}
root=pop();
inorder(root);
getch();
}
NODEPTR pop(NODEPTR p) {
if(top==0)
printf("Underflow condition !!");
else {
// printf("\npopped \n");
return(stc[top--]);
}
}
void push(NODEPTR p) {
if(top==29)
printf("Overflow condition !!");
else {
//printf("pushed ");
stc[++top]=p;
}
}
void getinput() {
printf("Enter a valid postfix string : ");
gets(expression);
}
void inorder(NODEPTR p)
{if(p!=NULL)
{
inorder(p->lnode);
printf("Data :%c",p->item);
inorder(p->rnode);
}
else
{printf("\nNull Tree");
return;}
}
Can anyone explain what mistake i made in the program ??.....pls its urgent and if possible please provide solutions..