Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Starter Code Here is part of the Tree class def. You need to find out what's missing and fill it in. class Tree { private:

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed
Starter Code Here is part of the Tree class def. You need to find out what's missing and fill it in." class Tree { private: struct Node { / / Inner class std: :string data; Node * sibling, *_child; static bool is_equal (const Node *pl, const Node *p2) ; Node (std: : string s = "") : // TODO Node (const Node &that) ; / / TODO const Node Goperator=(const Nodes that) ; // Deep clone ~Node () ; std: : string get_data () const { return data; } void set_data (std: :string s) { _data = s; } Node *insert_sibling (Node *p) ; Node *insert_child (Node *p) ; std: :string to_string () const; bool operator==(const Node &that) const; bool operator!=(const Node &that) const; Node * root; public: Tree () ; -Tree () ; Tree (const Trees that) { *this = that; } Trees operator=(const Trees that) ; // Deep clone std: :string to_string () const; void make_special_config 1 (const std: :vector& names) ;Your tenth miniquest - Tree copy Implement the copy constructor and the assignment operator, though not necessarily in that order. Tree (const Tree & that) ; Tree Soperator=(const Trees that) ; // Deep clone The assignment operator should clone the RHS tree (perform a deep copy). The copy constructor should simply invoke the assignment operator. Again, make sure to check for the special case when someone accidentally assigns a tree to itself. What would happen then if you were careless?Your eleventh miniquest - Tree comparisons Implement: bool operator== (const Tree &that) ; bool operator!=(const Tree &that) const; The == operator returns true if the two trees are structurally identical. Actual node pointers may be different. By structurally identical, I mean that they have the equal root nodes, where node equality is defined as in the earlier miniquest (I think 7). Your twelfth miniquest - Tree to string Implement: to_string () const; This is a very easy miniquest if you've managed to ace the Node : : to_string () miniquest. Otherwise... not so much. It is also an optional miniquest (return " to skip). Simply return the stringified version of the root wrapped within comment lines as shown below: # Tree rooted at [X] . # The following lines are of the form: # node: childl child2... [ . . .] + # End of Tree There is exactly one space before each word, except the word "node" on the last line where there are 3 spaces (gray rectangle). As before, the red X in square brackets must be replaced by the name of the root node (which should be ROOT if everything is set up right). . stands for a newline.Your thirteenth miniquest - Special tree This is a fun miniquest. All you have to do is to construct a Tree that looks like Fig 3. That's all. Implement the method: void make_special_config_1 (const vector & names) ; bool operator== (const Tree &that) const { // TODO bool operator!= (const Tree that) const { / / TODO friend std: : ostreams operator

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

Mobile Communications

Authors: Jochen Schiller

2nd edition

978-0321123817, 321123816, 978-8131724262

More Books

Students also viewed these Programming questions