AVL Tree Node Template In Data Structure Using C++

Data Structure Using C++

Tree Data Structure

AVL (Adelson-Velskii and Landis) Tree

AVL Node Template

template<class t>
class AVLNode
{
 private:
  t info;
  int height;
  AVLNode<t> *left;
  AVLNode<t> *right;
 public:
  AVLNode();
  AVLNode(t i);
  void setInfo(t i);
  t getInfo();
        void setHeight(int i);
  int getHeight();
  void setLeft (AVLNode<t> *);
  AVLNode<t>* getLeft ();
  void setRight (AVLNode<t> *);
  AVLNode<t>* getRight ();
};
// constructors
template<class t>
AVLNode<t>::AVLNode() 
{
 height=1;
 left=NULL;
 right=NULL;
}
template<class t>
AVLNode<t>::AVLNode(t i) 
{
 info=i;
 height=1;
 left=NULL;
 right=NULL;
}
template<class t>
t AVLNode<t>::getInfo()
{
 return info;
}
template<class t>
void AVLNode<t>::setInfo(t i) 
{ 
 info=i;
}
template<class t>
int AVLNode<t>::getHeight() 
{ 
 return height; 
}
template<class t>
void AVLNode<t>::setHeight(int h) 
{ 
 height=h;
}
template<class t>
void AVLNode<t>::setLeft (AVLNode<t> *ptr)
{
 left=ptr;
}
template<class t>
AVLNode<t> * AVLNode<t>::getLeft()
{
 return left;
}
template<class t>
void AVLNode<t>::setRight (AVLNode<t> *ptr)
{
 right=ptr;
}
template<class t>
AVLNode<t> * AVLNode<t>::getRight()
{
 return right;
}

Let me know in the comment section if you have any question.

Previous Post:
AVL Tree Node In Data Structure Using C++

Comments