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

  What do you meant by an rfp

Select a specific category of vertical applications to investigate. Use the Internet and any other sources of information you might have to study some of the different products that are available in that category.

  Creating a home inventory database

Construct one query of your selection. Remember a query answers a question. As an example, list all household electronics that are greater in value than $200.

  Choosing computer passwords

Before logging on to computer, you must have a unique username and unique password. Analyze and explain considerations you must make when choosing a password.

  Creating database for charity event

Your Project is to organize a charity event. You must use at least two events, one of which must be a Windows program such as Word, WordPad, or Paint.

  The radix sort algorithm

Show what happens to the radix sort algorithm if the counting sort is not a stable sorting algorithm. Bring a counter example

  Create all the possible combinations of array a

The subset-sum problem is defined as follows: given a set B of n positive integers and an integer K, can you find a subset of B whose elements' summation is equal to K? Design an algorithm to solve this problem. Address its correctness and running..

  Diagram of a telephone network

Consider a diagram of a telephone network, which is a graph G whose vertices represent switching centers, and whose edges represent communication lines joining pairs of centers. Edges are marked by their bandwidth, and the bandwidth of a path is the ..

  Write computer program to implement this algorithm

Write computer program to implement this algorithm and demonstrate the results and what is the machine run time in second for sorting array A?

  Computing randomized quick sort-s running time

Suppose that all element values are equal. What would be randomized quick sort's running time in this case? Each element of A[p .. q-1] is less than A[q], and each element of A[t+1 .. r] is greater than A[q]

  Consider a queue data structure

Consider a queue data structure, where the two operations of interest are enqueue (at the back of the queue) and dequeue (from the front of the queue). A queue is thus a FIFO (first in-first out) structure. Suppose we implement a queue by using tw..

  Write the relation r as a set if ordered pairs

let A={a,b,c,d,e} and suppose R is an equivalence relation on A . Suppose R has two equivalence classes. also aRd ,bRc and eRd in R . WRITE the relation R as a set if ordered pairs

  Evaluate the average complexity of an enqueue operation

Evaluate the average complexity of an enqueue operation. Determine the average complexity of the dequeue (remove) operation.

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