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

Ds 1

Uploaded by

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

Ds 1

Uploaded by

mpbhoir2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Name – Manasi Pravin Bhoir

Roll no – 02

Class – SE _D

Aim : Convert an Infix expression to Postfix expression using stack ADT

Theory :

#include<stdio.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;

You might also like