Académique Documents
Professionnel Documents
Culture Documents
DIVYA
REG.NO:21609104022.
DATE:
Program Coding:
#include<stdio.h>
struct node
{
char data;
tree left,right;
}*t=NULL;
tree stack[20];
char postf[20];
int top=-1;
void conversion();
void infix(tree);
void prefix(tree);
void postfix(tree);
void push(tree);
tree pop();
main()
{
void conversion()
{
int i;
NAME:R.DIVYA.
REG.NO:21609104022.
char x;
tree a,b,c;
for(i=0;postf[i]!='#';i++)
{
x=postf[i];
if(operand(x))
{
a=(tree)malloc(sizeof(struct node));
a->data=x;
a->left=NULL;
a->right=NULL;
push(a);
}
else
{
a=pop();
b=pop();
c=(tree)malloc(sizeof(struct node));
c->data=x;
c->left=b;
c->right=a;
push(c);
}
}
t=stack[top];
void push(tree a)
{
top++;
stack[top]=a;
tree pop()
{
tree a;
if(top==-1)
printf("\nThe Stack is empty");
else
{
a=stack[top];
top--;
}
return(a);
void infix(tree t)
{
NAME:R.DIVYA.
REG.NO:21609104022.
if(t!=NULL)
{
infix(t->left);
printf("%c",t->data);
infix(t->right);
}
void prefix(tree t)
{
if(t!=NULL)
{
printf("%c",t->data);
prefix(t->left);
prefix(t->right);
}
void postfix(tree t)
{
if(t!=NULL)
{
postfix(t->left);
postfix(t->right);
printf("%c",t->data);
}
}
NAME:R.DIVYA.
REG.NO:21609104022
Output:
Infix Traversal:
a+b*c*d+e
Prefix Traversal:
*+ab*c+de
Postfix Traversal:
ab+cde+**