Infix expression into the postfix expression, Data Structure & Algorithms

Assignment Help:

Q. Write down an algorithm to convert an infix expression into the postfix expression.    

Ans.

Algorithm to convert infix expression to post fix expression is given as follows.

1. opstk = the empty stack;

2. while (not end of input) {

3. symb = next input character;

4. if (symb is an operand) add symb to postfix string

5. else {

6. while (!empty (opstk) and prcd (top (opstk), symb)>0){

7. topsymb = pop(opstk);

8. add topsymb to the postfix string; }/*end while*/

9. if (empty (opstk) || symb! = ')' ) push (opstk, symb); else /*pop the open parenthesis and discard it */

topsymb = pop(opstk);

} /* end else */

}/* end while */

/* output any remaining operator */

10.while (!empty (opstk)){

11. top symb = pop (opstk);

12. add topsymb to the postfix string;

} /* end while * /

/*output any remaining operator*/


Related Discussions:- Infix expression into the postfix expression

Stack, write pseudocode to implement a queue with two stacks

write pseudocode to implement a queue with two stacks

Explain about the containers, Containers Introduction Simple abstr...

Containers Introduction Simple abstract data types are useful for manipulating simple sets of values, such as integers or real numbers however more complex abstract data t

State the term access restrictions - container, What is Access Restriction...

What is Access Restrictions Structured containers with access restrictions only allow clients to add, remove and examine elements at certain locations in their structure. For

Multiple stack, implement multiple stack in single dimensionl array.write a...

implement multiple stack in single dimensionl array.write algorithms for various stack operation for them

Multiqueue, data structure for multiqueue

data structure for multiqueue

Consistent heuristic function - graph search, Consistent Heuristic Function...

Consistent Heuristic Function - Graph Search Recall the notions of consistency and admissibility for an A* search heuristic. a. Consider a graph with four nodes S, A, B, C,

Program, insertion and deletion in a tree

insertion and deletion in a tree

Define order of growth, Define order of growth The  efficiency  analysi...

Define order of growth The  efficiency  analysis  framework  concentrates   on  the  order  of  growth  of  an  algorithm's   basic operation count as the principal indicator o

Define about the structure - container, Define about the Structure - Contai...

Define about the Structure - Container - Some containers hold elements in some sort of structure, and some don't. Containers with no structure include bags and sets. Containe

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd