Reference no: EM13311819
Write a C++ program that creates and populate a tree for an arithmetic expression. Then it should perform an in-order and a post-order traversal on the tree. The input of the program will be a text file with the arithmetic expressions in RPN.
The output of the program will be a printout of the arithmetic expression written out in both in-fix and post-fix (Reverse Polish) notations. The program does not need to compute the value of the expressions, only print them out.
Note: - The in-fix notation must have all brackets in the right places i.e. the in-order traversal must be modified to achieve this.
- The post-fix print out is useful for debugging purposes, as it should look like the original text file.
- You need to use a stack that is able to store Tree pointers. You can modify the Stack we developed in class, or use STL.
Remember that you can use the following algorithm to build the tree out of a file with the post-fixnotation:
An algorithm to construct an arithmetic tree
Read in an expression that is already in post-fix notation.
Tree *T1, *T2, *T; Stack S; //note that S is a stack of pointers to trees
while (expression continues) {
x = next item from the expression
if (x is a number) { S.Push(new Tree(x, NULL, NULL)); }
if (x is an operator) {
T1 = S.Top(); S.Pop();
T2 = S.Top(); S.Pop();
S.Push(new Tree(x, T2, T1)); //note order of T2 and T1
}
}
T = S.Top();
Submit a one file code on Stream by 6pm on Wednesday 2 of May 2013.Your name and ID number must appear on top of the file as comments.
If you are working in a group then all names and IDs must appear on top of the file as comments. Submit one file per group on Stream.
Explain low resolution absorption spectra to obtain values
: How to to use low resolution absorption spectra to obtain values proportional to the true absorbance
|
Evaluate the pressure of the gas if its volume
: Calculate the pressure of the gas if its volume is changed to 891 mL while its temperature is held constant. a) The pressure is 0.00253 atm. b) The pressure is 0.00428 atm. c) The pressure is 0.635 atm. d) The pressure is 1.57 atm. e) The pressure..
|
Describe one molecule or ion of perchlorate ion
: Choose the selection which gives the correct number of and bonds present in one molecule or ion of perchlorate ion, ClO4-. Make the central atom in your Lewis structure follow the octet rule if possible.
|
What leadership traits were apparent
: What is the situation and who are the leader(s) and follower(s) and what leadership traits were apparent and what lessons do you take away from this example?
|
Write a c++ program that creates and populate a tree
: Write a C++ program that creates and populate a tree for an arithmetic expression. Then it should perform an in-order and a post-order traversal on the tree. The input of the program will be a text file with the arithmetic expressions in RPN.
|
Explain hybridization and the central atom of bcl4
: Choose the selection which correctly identifies the sets of hybrid orbitals used by central atoms to form bonds in both of the molecules and/or ions whose formulas are given below: IF4- and BCl4-
|
What is the speed of the apple
: A 113 gram apple falls from a branch that is 2.5 meters above the ground. Just before the impact, what is the speed of the apple
|
What was the rock''s velocity
: In outer space a rock of mass 8 kg is acted on by a constant net force N during a 5 s time interval. What was the rock's velocity at the beginning of the time interval
|
State the equation showing the s-trans
: write the equation showing the S-trans to S-cis equilibrium of the two conformations for a. (E)-1,3-pentadiene b. (Z)-1,3-pentadiene
|