answersLogoWhite

0


Best Answer

#include<stdio.h>

#include<conio.h>

#include<string.h>

char symbol,s[10];

int F(symbol)

{

switch(symbol)

{

case '+':

case '-':return 2;

case '*':

case '/':return 4;

case '^':

case '$':return 5;

case '(':return 0;

case '#':return -1;

default :return 8;

}

}

int G(symbol)

{

switch(symbol)

{

case '+':

case '-':return 1;

case '*':

case '/':return 3;

case '^':

case '$':return 6;

case '(':return 9;

case ')':return 0;

default: return 7;

}

}

void infix_to_postfix(char infix[],char postfix[])

{

int top=-1,j=0,i,symbol;

s[++top]='#';

for(i=0;i<strlen(infix);i++)

{

symbol=infix[i];

while(F(s[top])>G(symbol))

{

postfix[j]=s[top--];

j++;

}

if(F(s[top])!=G(symbol))

s[++top]=symbol;

else

top--;

}

while(s[top]!='#')

{

postfix[j++]=s[top--];

}

postfix[j]='\0';

}

void main()

{

char infix[30],postfix[30];

clrscr();

printf("Enter the valid infix expression\n");

scanf("%s",infix);

infix_to_postfix(infix, postfix);

printf("postfix expression is \n %s", postfix);

getch();

}

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Prefix to postfix conversion using C programming?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the definition conversion?

to take and accepted unit of measurement and using the system that its involved with change the prefix


What does C plus C mean?

In terms of the C++ programming language itself, C++ literally means "the successor to C". In terms of the operator, operator++ is the increment operator. It has two forms: prefix (++c) and postfix (c++). Both do exactly the same thing and are effectively shorthand for the more verbose c = c + 1 or the more concise c += 1. The difference between the the prefix and postfix versions is in their evaluation. ++c will evaluate to c + 1 while c++ evaluates to c (the value of before the increment). However, the evaluations are only of importance when used in compound expressions: int a, b, c = 42; a = c++; // a==42, c==43 b = ++c; // b==44, c==44 Where the evaluation is of no importance, we can use either form. However, for user-defined types, the postfix operator usually incurs an overhead. This can be demonstrated by the following minimal example: struct foo { int i; foo&amp; operator++ () { // prefix increment ++i; // increment this-&gt;i return *this; // return the incremented object } foo&amp; operator++ (int) { // postfix increment foo f {*this}; // copy this object ++i; // increment this-&gt;i return f; // return the pre-incremented object } // ... }; Note that in both cases, the object itself is incremented, the only difference is in what value is returned to the caller (the newly incremented object or the original non-incremented object). However, because postfix increment requires that we copy the original value, we incur an overhead. The more complex the object, the greater that overhead will be. Built-in types do not suffer the copy overhead because the copy can be factored away by the compiler. Even so, it's a good idea to get into the habit of using prefix increment for built-in types unless you have good reason to use postfix increment. Similarly, it is usually a good idea to omit the postfix operator from user-defined classes unless we have good reason to provide it. Note that the postfix operator has an unused int argument in order to differentiate it from the prefix operator. The way to remember which is which is that the prefix operator has no argument, which is in common with all the other unary member operators. The postfix operator is the anomaly, thus it gets the dummy argument. The prefix and postfix decrement operators (operator--) work in a similar way, except they decrement the operand rather than increment it.


C plus plus program using a stacks converting a postfix-infix?

Yes


Sample program of postfix to infix?

You can convert from postfix to infix through the use of stacks. Consider the following expression conversion:54+67*+ -> ((5+4)+(6*7))The way this can be achieved is that whenever you encounter an operator, pop the last two expressions and join them using the operator. Remember to include the open braces before the first expression and a close braces after the second expression. Check the given link below for the program:


What has the author S Lakshmivarahan written?

S. Lakshmivarahan has written: 'Analysis and Design of Parallel Algorithms' -- subject(s): Parallel algorithms, Parallel programming (Computer science), Programming, Supercomputers 'Parallel computing using the prefix problem' -- subject(s): Computer algorithms, Parallel programming (Computer science)


Infix to postfix C?

Infix Expression :Any expression in the standard form like "2*3-4/5" is an Infix(Inorder) expression.Postfix Expression :The Postfix(Postorder) form of the above expression is "23*45/-".Infix to Postfix Conversion :In normal algebra we use the infix notation like a+b*c. The corresponding postfix notation is abc*+. The algorithm for the conversion is as follows :Scan the Infix string from left to right.Initialise an empty stack.If the scannned character is an operand, add it to the Postfix string. If the scanned character is an operator and if the stack is empty Push the character to stack. If the scanned character is an Operand and the stack is not empty, compare the precedence of the character with the element on top of the stack (topStack). If topStack has higher precedence over the scanned character Pop the stack else Push the scanned character to stack. Repeat this step as long as stack is not empty and topStack has precedence over the character.Repeat this step till all the characters are scanned.(After all characters are scanned, we have to add any character that the stack may have to the Postfix string.) If stack is not empty add topStack to Postfix string and Pop the stack. Repeat this step as long as stack is not empty.Return the Postfix string.Example :Let us see how the above algorithm will be imlemented using an example.Infix String : a+b*c-dInitially the Stack is empty and our Postfix string has no characters. Now, the first character scanned is 'a'. 'a' is added to the Postfix string. The next character scanned is '+'. It being an operator, it is pushed to the stack.StackPostfix StringNext character scanned is 'b' which will be placed in the Postfix string. Next character is '*' which is an operator. Now, the top element of the stack is '+' which has lower precedence than '*', so '*' will be pushed to the stack.StackPostfix StringThe next character is 'c' which is placed in the Postfix string. Next character scanned is '-'. The topmost character in the stack is '*' which has a higher precedence than '-'. Thus '*' will be popped out from the stack and added to the Postfix string. Even now the stack is not empty. Now the topmost element of the stack is '+' which has equal priority to '-'. So pop the '+' from the stack and add it to the Postfix string. The '-' will be pushed to the stack.StackPostfix StringNext character is 'd' which is added to Postfix string. Now all characters have been scanned so we must pop the remaining elements from the stack and add it to the Postfix string. At this stage we have only a '-' in the stack. It is popped out and added to the Postfix string. So, after all characters are scanned, this is how the stack and Postfix string will be :StackPostfix StringEnd result :Infix String : a+b*c-dPostfix String : abc*+d-


Example program of how to convert infix notation to postfix notation and prefix notation?

/**************************//**********cReDo**********//*****mchinmay@live.com***///C PROGRAM TO CONVERT GIVEN VALID INFIX EXPRESSION INTO POSTFIX EXPRESSION USING STACKS.#include#include#include#define MAX 20char stack[MAX];int top=-1;char pop();void push(char item);int prcd(char symbol){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 ')':return 1;break;default:return 0;}}void convertip(char infix[],char postfix[]){int i,symbol,j=0;stack[++top]='#';for(i=0;iprcd(stack[top]))push(symbol);else{while(prcd(symbol)


How was Minecraft made?

Notch wrote Minecraft using the Java programming language.


How do you convert infix to postfix without using data structures?

Without data-structures you cannot even store expressions, let alone convert or evaluate them.


How is control flow used to solve problems using computer programming?

How is control flow used to solve problems using computer programming


How do you write a sentence using the word prefix?

Find the prefix of the following words. The prefix of that word is the root "dis-"


Is MySQL a programming language?

MySQL was written and developed using the C and C++ programming languages.