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

  Implement an open hash table

In this programming assignment you will implement an open hash table and compare the performance of four hash functions using various prime table sizes.

  Use a search tree to find the solution

Explain how will use a search tree to find the solution.

  How to access virtualised applications through unicore

How to access virtualised applications through UNICORE

  Recursive tree algorithms

Write a recursive function to determine if a binary tree is a binary search tree.

  Determine the mean salary as well as the number of salaries

Determine the mean salary as well as the number of salaries.

  Currency conversion development

Currency Conversion Development

  Cloud computing assignment

WSDL service that receives a request for a stock market quote and returns the quote

  Design a gui and implement tic tac toe game in java

Design a GUI and implement Tic Tac Toe game in java

  Recursive implementation of euclids algorithm

Write a recursive implementation of Euclid's algorithm for finding the greatest common divisor (GCD) of two integers

  Data structures for a single algorithm

Data structures for a single algorithm

  Write the selection sort algorithm

Write the selection sort algorithm

  Design of sample and hold amplifiers for 100 msps by using n

The report is divided into four main parts. The introduction about sample, hold amplifier and design, bootstrap switch design followed by simulation results.

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