Write a c++ program that creates and populate a tree

Assignment Help Data Structure & Algorithms
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.

Reference no: EM13311819

Questions Cloud

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

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Hash values

Suppose these names have the following hash values. Insert them into the extendible hash table shown below. Each leaf can only hold 4 entries.

  Shell scripting based questions

Determine will the following only print the text "I FOUND A MATCH" to standard output when the grep is successful? if grep "mrichard" /etc/passwd; then echo "I FOUND A MATCH"; fi

  Design a nonrecursive algorithm

Design a nonrecursive algorithm that visits all the nodes of a general multiway tree in level order: that is, level-by-level, going left-to-right across a level.

  Created a linked list class

created a linkedlist class

  Develop a business systems plan

Develop a Business Systems Plan (with full justification as to how these are applicable for the organisation) so as to accommodate mobile access to various services provided by the hospital.

  Prepare a report about leased circuits

COMP6011 Data Communications -  Prepare a report about Leased circuits

  Give an algorithm that takes an n-node path g with weights

Give an algorithm that takes an n-node path G with weightsand returns an independent set of maximum total weight. The runningtime should be polynomial in n, independent of the values of theweights

  Write control structure-pseudocode algorithm for simple task

Three simple control structures which could be used to make this algorithm. What do you believe is most difficult part of creating algorithm?

  Write a procedure hamming

Write a procedure hamming(ascii, encoded) that converts the low-order 7 bits of ascii into an 11-bit integer codeword stored in encoded.

  Create a shell script the count the number of files

Create a shell script that will calculate the number of files in your account hat were last modified five or more days ago and when you run the shell script,

  Conduct time complexity analysis of the algorithm

Hand test your algorithm using your allocated 10-element long list of alphabetic charactersas an illustrative/working example (see the Data Set below),

  Simplify rsa cryptosystem using prime number

Assume we tried to simplify RSA cryptosystem using just prime p instead of composite modulus N = pq. As in RSA, we would have encryption exponent.

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