1 / 3

Stacks

Stacks. Use stacks to convert infix into postfix expressions. CS204 Assignment 3 Due Date: 10/28. Problem Solving.

thais
Download Presentation

Stacks

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Stacks Use stacks to convert infix into postfix expressions CS204 Assignment 3 Due Date:10/28

  2. Problem Solving The goal of the program is to write a code which will convert an infix expression into a postfix format. Before the program can be developed it is required to know which operations come first when performing a calculation. There are several rules that must be followed such as: • Scan the input string in infix form from left to right. • If the next symbol is scanned is an operand, it may be immediately appended to the postfix string. • If the next symbol is an operator : • Pop and append to the postfix string every operator on the stack that • Is above the most recently scanned ( and • Has precedence higher than or = to that of new operator symbol 2) Push the new operator symbol onto the stack • 4) When an ( is seen it must be pushed on to the stack • When a closing ) is seen all operators down to the most recently scanned ( must be popped and appended to the postfix string • When the infix string is completely scanned, the stack may still contain some operators.

  3. Behavior • Desired behavior • There will be input file created by the user which will contain a list of infix expressions each one followed by a ; the last expression will conation a . At the end • When the program executes it will read in an infix string from the input file and perform the desired operation needed according to the rules. The operations which it will use are ( ) / * + - All or a few of these operations will be inside a infix string expression. The driver program will put the right character onto the stack or queue. • The output will be sent to an output file. Output file will contain the original infix notation followed by the postfix expression. Each expression will be appropriately be labeled before the expression is printed to the file.

More Related