Question: #ifndef AVLTREE_H #define AVLTREE_H #include Data.h template class AVLTree { private: struct AVLNode { AVLNode* leftChild; AVLNode* rightChild; T* data; int duplicates; // used if

#ifndef AVLTREE_H

#define AVLTREE_H

#include "Data.h"

template

class AVLTree {

private:

struct AVLNode {

AVLNode* leftChild;

AVLNode* rightChild;

T* data;

int duplicates; // used if there are duplicate values in the tree

// instead of changing rotation rules

int height;

AVLNode () : // default constructor

leftChild {nullptr},

rightChild {nullptr},

data {nullptr},

duplicates {0},

height {0} {};

~AVLNode () = default;

AVLNode (T& value) :

leftChild {nullptr},

rightChild {nullptr},

duplicates {0},

height {0} {

data = new T{value};

};

AVLNode (T&& value):

leftChild {nullptr},

rightChild {nullptr},

duplicates {0},

height {0} {

data = new T{value};

}

AVLNode (T& value, AVLNode* left, AVLNode* right) :

leftChild {left},

rightChild {right},

duplicates {0},

height {0} {

data = new T{value};

};

AVLNode (T&& value, AVLNode* left, AVLNode* right) :

leftChild {left},

rightChild {right},

duplicates {0},

height {0} {

data = new T{value};

}

};

AVLNode* root;

// method to clone a subtree and return it.

AVLNode* clone (AVLNode* node) const {

if (!node){

return nullptr;

} else {

AVLNode* temp = new AVLNode (*node->data,

clone(node->leftChild),

clone(node->rightChild));

temp->duplicates = node->duplicates;

temp->height = getHeight(node);

return temp;

}

}

// Possibly several functions to be used by printing traversal functions

// (below). These functions may need to know what the last leaf in a

// subtree is to print nicely (by my standards, anyway).

// CODE HERE

// should print the tree in a preorder traversal

void printPreorder(AVLNode* node) const {

// CODE HERE

}

// should print the tree in an inorder traversal

void printInorder(AVLNode* node) const {

// CODE HERE

}

// should print the tree in a postorder traversal

void printPostorder(AVLNode* node) const {

// CODE HERE

}

//Data.h------------------------

#ifndef DATA_H

#define DATA_H

#include

class DoubleData {

private:

double* data;

public:

DoubleData();

DoubleData(double a);

~DoubleData() = default;

// accessors -------------------------------

double getData() const ;

double compare(DoubleData& other) const;

friend std::ostream& operator<<(std::ostream& os, const DoubleData& dd);

// mutators --------------------------------

void setData(double _data);

};

#endif

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!