"infix to prefix in c" Code Answer's

You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "infix to prefix in c" answered properly. Developers are finding an appropriate answer about infix to prefix in c related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like infix to prefix in c. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on infix to prefix in c. 

infix to prefix in c

By Real RatReal Rat on Mar 17, 2021
# include <stdio.h># include <string.h># define MAX 20void infixtoprefix(char infix[20],char prefix[20]);void reverse(char array[30]);char pop();void push(char symbol);int isOperator(char symbol);int prcd(symbol);int top=-1;char stack[MAX];main() {	char infix[20],prefix[20],temp;	printf("Enter infix operation: ");	gets(infix);	infixtoprefix(infix,prefix);	reverse(prefix);	puts((prefix));}//--------------------------------------------------------void infixtoprefix(char infix[20],char prefix[20]) {	int i,j=0;	char symbol;	stack[++top]='#';	reverse(infix);	for (i=0;i<strlen(infix);i++) {		symbol=infix[i];		if (isOperator(symbol)==0) {			prefix[j]=symbol;			j++;		} else {			if (symbol==')') {				push(symbol);			} else if(symbol == '(') {				while (stack[top]!=')') {					prefix[j]=pop();					j++;				}				pop();			} else {				if (prcd(stack[top])<=prcd(symbol)) {					push(symbol);				} else {					while(prcd(stack[top])>=prcd(symbol)) {						prefix[j]=pop();						j++;					}					push(symbol);				}				//end for else			}		}		//end for else	}	//end for for	while (stack[top]!='#') {		prefix[j]=pop();		j++;	}	prefix[j]='\0';}////--------------------------------------------------------void reverse(char array[30]) // for reverse of the given expression {	int i,j;	char temp[100];	for (i=strlen(array)-1,j=0;i+1!=0;--i,++j) {		temp[j]=array[i];	}	temp[j]='\0';	strcpy(array,temp);	return array;}//--------------------------------char pop() {	char a;	a=stack[top];	top--;	return a;}//----------------------------------void push(char symbol) {	top++;	stack[top]=symbol;}//------------------------------------------int prcd(symbol) // returns the value that helps in the precedence {	switch(symbol) {		case '+':		        case '-':		        return 2;		break;		case '*':		        case '/':		        return 4;		break;		case '$':		        case '^':		        return 6;		break;		case '#':		        case '(':		        case ')':		        return 1;		break;	}}//-------------------------------------------------int isOperator(char symbol) {	switch(symbol) {		case '+':		        case '-':		        case '*':		        case '/':		        case '^':		        case '$':		        case '&':		        case '(':		        case ')':		        return 1;		break;		default:		        return 0;		// returns 0 if the symbol is other than given above	}}

Source: scanftree.com

Add Comment

0

All those coders who are working on the Whatever based application and are stuck on infix to prefix in c can get a collection of related answers to their query. Programmers need to enter their query on infix to prefix in c related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about infix to prefix in c for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of infix to prefix in c while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "infix to prefix in c". Visit this developer's friendly online web community, CodeProZone, and get your queries like infix to prefix in c resolved professionally and stay updated to the latest Whatever updates. 

Whatever answers related to "infix to prefix in c"

View All Whatever queries

Whatever queries related to "infix to prefix in c"

Browse Other Code Languages

CodeProZone