Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

// Struct for nodes of the tree template struct node { T key; S value; shared_ptr child; shared_ptr sibling; node(T key, S value) { this->key

// Struct for nodes of the tree

template

struct node {

T key;

S value;

shared_ptr> child;

shared_ptr> sibling;

node(T key, S value) {

this->key = key;

this->value = value;

child = NULL;

sibling = NULL;

}

};

// Constructor

template

Tree::Tree(shared_ptr> root) {

this->root = root;

}

// This function finds a key in the tree and returns the respective node

template

shared_ptr> Tree::findKey(T key) {

return findKeyHelper(root,key);

}

// Helper function to find a key in the tree

template

shared_ptr> Tree::findKeyHelper(shared_ptr> currNode, T key) {

return NULL;

}

// This function inserts the given node as a child of the given key

template

bool Tree::insertChild(shared_ptr> newNode, T key) {

return false;

}

// This function returns all the children of a node with the given key

template

vector>> Tree::getAllChildren(T key) {

return vector>>();

}

// This function returns the height of the tree

template

int Tree::findHeight() {

return findHeightHelper(root);

}

// Helper function to find height of the tree

template

int Tree::findHeightHelper(shared_ptr> currNode) {

return 0;

}

// This function deletes the node of a given key (iff it is a leaf node)

template

bool Tree::deleteLeaf(T key) {

return false;

}

// Helper function to delete leaf node

template

shared_ptr> Tree::deleteLeafHelper(shared_ptr> currNode, T key) {

return NULL;

}

// This function deletes the tree

template

void Tree::deleteTree(shared_ptr> currNode) {

return;

}

// This function returns the root of the tree

template

shared_ptr> Tree::getRoot() {

return NULL;

}

Code all of these in c++

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_2

Step: 3

blur-text-image_3

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2018 Dublin Ireland September 10 14 2018 Proceedings Part 1 Lnai 11051

Authors: Michele Berlingerio ,Francesco Bonchi ,Thomas Gartner ,Neil Hurley ,Georgiana Ifrim

1st Edition

3030109240, 978-3030109240

More Books

Students also viewed these Databases questions