Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PART 1 GENERAL TREES In this part you will be implementing a general tree data structure where each node of a tree can have any

image text in transcribed

image text in transcribed

PART 1 GENERAL TREES In this part you will be implementing a general tree data structure where each node of a tree can have any number of children nodes. Refer to tree.hpp which provides all the required definitions. Write your implementation in tree.cpp using the boiler code. Member Functions: Write implementation for the following methods as described here: Tree (shared_ptr> root) Constructor . shared_ptr> findKey(T key) Finds the node with the given key and returns a pointer to that node. NULL is returned if the key doesn't exist shared_ptr> findKeyHelper (shared_ptr> currNode, T key) Helper function to be used in findkey(T key) function bool insertChild(shared_ptr> newNode, T key) Inserts the given node as the child of the given key. Returns true if insertion is successful and false if key doesn't exist. Insertion should also fail if another node with the same key as the new node already exists i.e. duplicates are not allowed. If the node at the given key already has children, the new node must be added to the tail of the children of that node. vector>> getAllChildren (T key) Returns all the children of the node with the given key. Should return an empty vector in case the node has no child or key doesn't exist. int findHeight() Returns the height of the tree int findHeightHelper (shared_ptr> curr Node) In this assignment, you are free to declare any helper functions as per your need but the already declared function declarations should not be modified. Helper function to be used in the findHeight() function void deleteTree (shared_ptr> curr Node) Delete the entire tree. bool deleteLeaf (T key) Delete node with given key if and only if it is a leaf node i.e. have no child. Doesn't delete the root node even if it is the only node in the tree. Returns true on success, false on failure. shared_ptr> deleteLeafHelper (shared_ptr> curr Node, T key) Helper function to delete the leaf node. PART 1 GENERAL TREES In this part you will be implementing a general tree data structure where each node of a tree can have any number of children nodes. Refer to tree.hpp which provides all the required definitions. Write your implementation in tree.cpp using the boiler code. Member Functions: Write implementation for the following methods as described here: Tree (shared_ptr> root) Constructor . shared_ptr> findKey(T key) Finds the node with the given key and returns a pointer to that node. NULL is returned if the key doesn't exist shared_ptr> findKeyHelper (shared_ptr> currNode, T key) Helper function to be used in findkey(T key) function bool insertChild(shared_ptr> newNode, T key) Inserts the given node as the child of the given key. Returns true if insertion is successful and false if key doesn't exist. Insertion should also fail if another node with the same key as the new node already exists i.e. duplicates are not allowed. If the node at the given key already has children, the new node must be added to the tail of the children of that node. vector>> getAllChildren (T key) Returns all the children of the node with the given key. Should return an empty vector in case the node has no child or key doesn't exist. int findHeight() Returns the height of the tree int findHeightHelper (shared_ptr> curr Node) In this assignment, you are free to declare any helper functions as per your need but the already declared function declarations should not be modified. Helper function to be used in the findHeight() function void deleteTree (shared_ptr> curr Node) Delete the entire tree. bool deleteLeaf (T key) Delete node with given key if and only if it is a leaf node i.e. have no child. Doesn't delete the root node even if it is the only node in the tree. Returns true on success, false on failure. shared_ptr> deleteLeafHelper (shared_ptr> curr Node, T key) Helper function to delete the leaf node

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

Database Marketing The Ultimate Marketing Tool

Authors: Edward L. Nash

1st Edition

0070460639, 978-0070460638

More Books

Students also viewed these Databases questions

Question

Discuss the history of human resource management (HRM).

Answered: 1 week ago