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

Explain how two dimensional arrays are represented in memory, Explain how t...

Explain how two dimensional arrays are represented in memory. Representation of two-dimensional arrays in memory:- Let grades be a 2-D array as grades [3][4]. The array will

Explain the term heuristics searching, (a) Discuss the role played by Busin...

(a) Discuss the role played by Business Intelligence Systems in giving companies strategic advantage. (b) Explain the term heuristics searching . (c) With the use of an appr

Pseudocodes, how to draw a 5 inch square on the screen using * symbol

how to draw a 5 inch square on the screen using * symbol

Binary search tree, Objectives The purpose of this project is to give yo...

Objectives The purpose of this project is to give you significant exposure to Binary Search Trees (BST), tree traversals, and recursive code. Background An arbitrary BST i

Algorithm for sorting a deck of cards, What is wrong with the following alg...

What is wrong with the following algorithm for sorting a deck of cards (considering the basic properties of algorithms)? I. Put the cards together into a pile II. For each ca

Algorithm, Define what an algorithm is and outline the characteristics of a...

Define what an algorithm is and outline the characteristics of a good algorithm.

Algo for quicksort, Easy algorithm for beginner for quicksort with explanat...

Easy algorithm for beginner for quicksort with explanation

Explain the rgb model, RGB Model The RGB model is based on the assumpti...

RGB Model The RGB model is based on the assumption that any desired shade of colour can be obtained by mixing the correct amounts of red, green, and blue light. The exact hues

Insert function, INSERT FUNCTION /*prototypes of insert & find function...

INSERT FUNCTION /*prototypes of insert & find functions */ list * insert_list(list *); list * find(list *, int); /*definition of  anyinsert function */ list * inser

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