Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#ifndef AVLTREE_H #define AVLTREE_H #include \"Data.h\" template <typename T> cl

ID: 3912986 • Letter: #

Question

#ifndef AVLTREE_H

#define AVLTREE_H

#include "Data.h"

template <typename T>

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 <iostream>

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

Explanation / Answer

void printPreorder(AVLNode* node) const

{

       // CODE HERE

AVLNode* root;

printPreorder(node->leftChild);

printPreorder(node->rightChild);

   }

   // should print the tree in an inorder traversal

   void printInorder(AVLNode* node) const

{

printInorder(node->leftChild);

AVLNode* root;

printInorder(node->rightChild);

   }

   // should print the tree in a postorder traversal

   void printPostorder(AVLNode* node) const {

       // CODE HERE

printPostorder(node->leftChild);

printPostorder(node->rightChild);

AVLNode* root;

   }