0% found this document useful (0 votes)
8 views3 pages

Infix to Postfix Conversion in C

The document outlines an experiment to convert infix expressions to postfix notation using a stack in C programming. It includes an introduction to infix and postfix notations, a C code implementation for the conversion, and concludes that the program has been successfully created. The code handles operator precedence and parentheses during the conversion process.

Uploaded by

bro665444
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

Infix to Postfix Conversion in C

The document outlines an experiment to convert infix expressions to postfix notation using a stack in C programming. It includes an introduction to infix and postfix notations, a C code implementation for the conversion, and concludes that the program has been successfully created. The code handles operator precedence and parentheses during the conversion process.

Uploaded by

bro665444
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

EXPERIMENT – 5

AIM

Write a program to implement the conversion of infix to postfix expression using Stack.

INTRODUCTION

Infix notation is a way of writing arithmetic expressions in which the operators are placed between the
operands. For example, the infix notation of the expression “3 + 4” is “3 + 4”. Postfix notation, also
known as Reverse Polish Notation (RPN), is another way of writing arithmetic expressions in which the
operators are placed after the operands. For example, the postfix notation of the expression “3 + 4” is
“3 4 +”. To convert an infix expression to postfix, we can use the stack data structure.

C CODE

#include<stdio.h>

#include<ctype.h>

char stack[100];

int top = -1;

void push(char x)

stack[++top] = x;

char pop()

if(top == -1)

return -1;

else

return stack[top--];

int priority(char x)

if(x == ‘(‘)
return 0;

if(x == ‘+’ || x == ‘-‘)

return 1;

if(x == ‘*’ || x == ‘/’)

return 2;

return 0;

int main()

char exp[100];

char *e, x;

printf(“Enter the expression : “);

scanf(“%s”,exp);

printf(“\n”);

e = exp;

while(*e != ‘\0’)

if(isalnum(*e))

printf(“%c “,*e);

else if(*e == ‘(‘)

push(*e);

else if(*e == ‘)’)

while((x = pop()) != ‘(‘)

printf(“%c “, x);

else

while(priority(stack[top]) >= priority(*e))


printf(“%c “,pop());

push(*e);

e++;

while(top != -1)

printf(“%c “,pop());

}return 0;

RESULT

CONCLUSION

Infix to Postfix conversion program in c has been successfully made and implemented.

You might also like