Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Algorithm 1 Construct linked list from an infix expression Input: a fully parenthesized infix expression Output: the corresponding linked list Let cursor points to the

Algorithm 1 Construct linked list from an infix expression Input: a fully parenthesized infix expression Output: the corresponding linked list Let cursor points to the beginning of the string current = new node cursor = cursor.next while cursor is not the end of the string do if cursor == 0 ( 0 then create a new node n if current.left is null then current.left = n else current.right = n end if current = n else if cursor is an operator op then current.value = op else if cursor == x then current.left = x else if cursor is a constant c then current.right = c else if cursor == 0 ) 0 then current = current.parent end if cursor = cursor.next end while Functionality of the program Your program should have the following functionalities: 1. A method String infixString(): returns an infix string representation of the stored Expression 2. A method String prefixString(): returns a prefix string representation of the stored Expression 3. A method String postfixString(): returns a postfix string representation of the stored Expression The prefix representation of an expression shows the operator before the operands, for example the prefix representation of the infix ((x+ 2)+ (x3)) is ++x 2x 3. The postfix representation shows the operator after the operands, for example the postfix representation of the infix ((x+ 2) + (x 3)) is x 2 +x 3 +. Note that, unlike the infix representation, the prefix and postfix representation do not require parentheses to specify an order of computation. In the output of postfixString() and prefixString(), do not use parentheses. Implementation requirements To start gaining experience in how to structure your C++ projects, you are required to split the different aspects of this program and implement them in separate files. Then you will have to put them all back together to achieve the program functionality. By now, you should be familiar with the concept of .h and .cpp files (if not, it is a good moment to familiarize yourselves). You will need to create several .h and .cpp files for this project. We will help guiding you through this process. First you need to identify the important object-types and methods you will need for your implementation. In this project, your main object type is going to be class Node. Go ahead and create a file called node.h and declare class Node in it. The next step is to implement the functionality for creating the list (Algorithm 1). For this purpose, you need to create two more files - list.h and list.cpp. In list.h declare all the methods needed for building the list and in list.cpp define these methods. Then you should implement class Expression and implement the aforementioned methods, i.e, infixString(), prefixString(), and postfixString(). So, you need to create two more files - expression.h and expression.cpp. Now whats left is to put it all together by writing a main function. To do so, create string.h and string.cpp, declare your main function in string.h and define it in string.cpp. So all in all you will need eight files: node.h, node.cpp, list.h, list.cpp, expression.h, expression.cpp, string.h, and string.cpp.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Genomes And Databases On The Internet A Practical Guide To Functions And Applications

Authors: Paul Rangel

1st Edition

189848631X, 978-1898486312

More Books

Students also viewed these Databases questions