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

What is quick sort, What is quick sort?   Answer Quick sort is on...

What is quick sort?   Answer Quick sort is one of the fastest sorting algorithm used for sorting a list. A pivot point is chosen. Remaining elements are divided or portio

Two sparce matrices multipilcation algorithm, Write an algorithm for multi...

Write an algorithm for multiplication of two sparse matrices using Linked Lists.

Algorithm for determining strongly connected components, Algorithm for dete...

Algorithm for determining strongly connected components of a Graph: Strongly Connected Components (G) where d[u] = discovery time of the vertex u throughout DFS , f[u] = f

Graph with n vertices will absolutely have a parallel edge, A graph with n ...

A graph with n vertices will absolutely have a parallel edge or self loop if the total number of edges is greater than n-1

Advanced trees, Linked list representations contain great advantages of fle...

Linked list representations contain great advantages of flexibility on the contiguous representation of data structures. However, they contain few disadvantages also. Data structur

Quicksort and bubble sort algorithms, Task If quicksort is so quick, w...

Task If quicksort is so quick, why bother with anything else? If bubble sort is so bad, why even mention it? For that matter, why are there so many sorting algorithms? Your

Algorithm to insert element to a max-heap sequentially, Q. Write  down the ...

Q. Write  down the  algorithm  to  insert  an  element  to  a  max-heap  which  is  represented sequentially.           Ans: The algorithm to insert an element "newkey" to

Recurrence relation, solve the following relation by recursive method: T(n...

solve the following relation by recursive method: T(n)=2T(n^1/2)+log n

Singly linked list , The two pointers per number of a doubly linked list pr...

The two pointers per number of a doubly linked list prepare programming quite easy. Singly linked lists as like the lean sisters of doubly linked lists. We need SItem to consider t

Define binary tree, Define Binary Tree  A binary tree T is explained as...

Define Binary Tree  A binary tree T is explained as a finite set of nodes that is either empty or having of root and two disjoint binary trees TL, and TR known as, respectively

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