Theoretical Paper
- Computer Organization
- Data Structure
- Digital Electronics
- Object Oriented Programming
- Discrete Mathematics
- Graph Theory
- Operating Systems
- Software Engineering
- Computer Graphics
- Database Management System
- Operation Research
- Computer Networking
- Image Processing
- Internet Technologies
- Micro Processor
- E-Commerce & ERP
Practical Paper
Industrial Training
Infix To Prefix Conversion
Prefix/Postfix/Infix Notation
Postfix To Infix Conversion
In the last of the expression conversion series I am presenting a program to convert a Postfix expression to an Infix expression. Here it is...
#define Max 100
void pop (char*);
void push(char*);
char stack[MAX] [MAX];
int top = -1
main()
{
char s[MAX], str1[MAX], str2[MAX], str[MAX];
char s1[2],temp[2];
inti=0;
clrscr( ) ;
printf("\Enter the postfix expression; ")
get(s);
while (s[i]!`\0')
{
/*skip whitespace, if any*/
if(s[i] == ' ' )
i++;
if (s[i] == `%' || s[i] == `*'|| s[i] == `-' || s[i] == `+' || s[i] == `/')
{
pop(str1);
pop(str2);
temp[0] =`(';
temp[1] =`\0';
strcpy(str, temp);
strcat(str, str2);
temp[0] = s[i];
temp[1] = `\0'
strcat(str,temp);
strcat(str, str1);
temp[0] =`)';
temp[1] =`\0';
strcat(str,temp);
push(str);
}
else
{
temp[0]=s[i];
temp[1]=`\0';
strcpy(s1, temp);
push(s1);
}
i++;
}
printf("\n%s", stack[0]);
}
void pop(char *a1)
{
strcpy(a1,stack[top]);
top--;
}
void push (char*str)
{
if(top == MAX - 1)
printf("\nstack is full");
else
{
top++;
strcpy(stack[top], str);
}
}