# Implementation of Infix to Postfix expression

- Link: https://technotaught.com/implementation-of-infix-to-postfix-expression/
- Published: 2018-11-10T22:54:53+05:30
- Author: Ashishkumar Vishwakarma

In this article we will see Implementation of Infix to Postfix expression

## Implementation of Infix to Postfix expression

![infix to postfix](https://technotaught.com/wp-content/uploads/2018/11/Infix-to-
Posting-1024x577.png)

Also, you can use the C [compiler](https://www.onlinegdb.com/online_c_compiler) 
to compile a program.

Read more: – [Double Ended Queue or Deque](https://technotaught.com/double-ended-queue/)

### Source Code of infix to postfix in C

    ```c
    #include<conio.h>
    #include<stdio.h> 
    #include<stdlib.h> 
    #include<string.h> 
    #define SIZE 30 
    char stack[SIZE]; 
    int top=0; 
    char infix[SIZE]; 
    char postfix[SIZE]; 
    int p=0; void in2po(); 
    void push(char); 
    void pop(char); 
    int main() 
    { 
    	printf("infix: "); 
    	gets(infix); 
    	infix[strlen(infix)]='.'; 
    	in2po(); printf("postfix: "); 
    	puts(postfix); getch(); 
    } 

    void push(char c) 
    { 
    	if(top!=SIZE) { 
    		stack[top]=c; 
    		top++; 
    	} else { 
    		printf("Stack Overflow\n"); 
    		getch(); 
    		exit(EXIT_FAILURE); 
    	} 
    } 
    void pop(char c) 
    { 
    	if(top<0) { 
    		printf("Stack empty\n"); 
    		getch(); exit(EXIT_FAILURE); 
    	} else { 
    		switch(c) { 
    			case '^': while( top>0 && stack[top-1]=='^' ) { 
    					postfix[p]=stack[top-1]; 
    					top--; p++; 
    				} break; 
    			case '/': 
    			case '*': 
    				while( top>0 && (stack[top-1]=='^' || stack[top-1]=='/') ) { 
    					postfix[p]=stack[top-1]; 
    					top--; 
    					p++; 
    				} break; 
    			case ')': while( top>0 && stack[top-1]!='(' ) { 
    				postfix[p]=stack[top-1]; 
    				top--; p++; 
    				} top--; 
    				break; 
    			case '.': while( top>0 ) { 
    				postfix[p]=stack[top-1]; 
    				top--; p++; 
    				} break; 
    			} 
    		} 
    	} 
    void in2po() { 
    	int i=0; 
    	char c; 
    	while(i<strlen(infix)) 
    	{ 
    		c = infix[i]; 
    		switch(c) { 
    			case '+': 
    			case '-': 
    			case '(' : push(c); break; 
    			case '.': case ')': pop(c); 
    				break; 
    			case '/': 
    			case '^': 
    			case '*': 
    				pop(c); 
    				push(c); 
    				break; 
    			default: postfix[p]=c; 
    				p++; 
    		} 
    		i++; 
    	} 
    }
    ```

 

Related: – [Stack using Linked List.](https://technotaught.com/stack-using-linked-list/)

### Output.

> infix: a+b+c
> postfix: abc++

#### Or

> infix: a-b+c
> postfix: abc+-

### Share this:

 * [  X ](https://technotaught.com/implementation-of-infix-to-postfix-expression/?share=twitter)
 * [  Facebook ](https://technotaught.com/implementation-of-infix-to-postfix-expression/?share=facebook)
 * [More](https://technotaught.com/implementation-of-infix-to-postfix-expression/#)

 * [  WhatsApp ](https://technotaught.com/implementation-of-infix-to-postfix-expression/?share=jetpack-whatsapp)
 * [  LinkedIn ](https://technotaught.com/implementation-of-infix-to-postfix-expression/?share=linkedin)
 * [  Email ](https://technotaught.com/implementation-of-infix-to-postfix-expression/?subject=%5BShared%20Post%5D%20Implementation%20of%20Infix%20to%20Postfix%20expression&body=https%3A%2F%2Ftechnotaught.com%2Fimplementation-of-infix-to-postfix-expression%2F&share=email)
 * [  Reddit ](https://technotaught.com/implementation-of-infix-to-postfix-expression/?share=reddit)
 * [  Tumblr ](https://technotaught.com/implementation-of-infix-to-postfix-expression/?share=tumblr)
 * [  Pinterest ](https://technotaught.com/implementation-of-infix-to-postfix-expression/?share=pinterest)
 * [  Telegram ](https://technotaught.com/implementation-of-infix-to-postfix-expression/?share=telegram)
 * [  Print ](https://technotaught.com/implementation-of-infix-to-postfix-expression/#print?share=print)

### _Related_

## Comments

### By: Lucas Rogers

- Link: https://technotaught.com/implementation-of-infix-to-postfix-expression/#comment-115
- Published: 2020-04-15T22:20:19+05:30

Incredible points. Sound arguments. Keep up the great work.
