Posts

Showing posts with the label stack

Infix To Postfix Conversion in C

Image
This post is all about the conversion of an infix expression to a postfix expression. This program is basically implemented with a stack. This program is done using the c language. Here the main element is the precedence of the operator and the parentheses ! Screenshots[Demo] The Code #define SIZE 50 /* Size of Stack */ #include <ctype.h> char s[SIZE]; int top=-1; /* Global declarations */ push(char elem) { /* Function for PUSH operation */ s[++top]=elem; } char pop() { /* Function for POP operation */ return(s[top--]); } int pr(char elem) { /* Function for precedence */ switch(elem) { case '#': return 0; case '(': return 1; case '+': case '-': return 2; case '*': case '/': return 3; } } int main() { /* Main Program */ char infx[50],pofx[50],ch,elem; int i=0,k=0; printf(...