CS2134_HW5 - Homework#5 Due 11:59 p.m Tuesday Nov 6 In...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Homework #5 Due 11:59 p.m., Tuesday Nov 6 In class we studied an algorithm that converts infix expressions to postfix and an algorithm that evaluates postfix expressions. In this programming assignment, you’ll write a program to convert postfix expressions to (fully parenthesized) infix. It is closely related to the algorithm to evaluate postfix expressions. Rather than maintaining a stack of numbers, the program will maintain a stack of strings, each representing an infix expression. Scan the input from left to right, performing the following actions: 1. Read next token and determine whether it represents a number or an operator symbol 2. if the token is a number, create a string that represents the number and push it onto the stack 3. if the token is a binary operator symbol (+,-,*,/) 1. pop two strings (representing sub-expressions) from the stack 2. create a string of the form “( s1 op s2)”, where s1 and s2 are the popped strings and op is the new operator symbol 3. push the resulting string back onto the stack 4. if the token is a period, it denotes the end of the input When you’ve finished scanning the input, the stack should contain a single string representing the infix expression, provided that the input was a valid postfix expression.
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern