Advanced Programming - Binary Search Tree
A simple Binary Search Tree implementation for the Advanced Programming 2019-2020 course @ SISSA.
Public Member Functions | Public Attributes | List of all members
APutils::Node< T > Struct Template Reference

Class that implements a node of a tree. More...

#include <Node.hpp>

Public Member Functions

 Node () noexcept
 Void constructor. More...
 
 Node (const T &data, Node< T > *parent) noexcept
 Copy constructor with data. More...
 
 Node (T &&data, Node< T > *parent) noexcept
 Move constructor with data. More...
 
void printNode (std::ostream &os, const bool &printChildren)
 Utility function that prints a Node. More...
 
void printNode ()
 Utility function that prints a Node. More...
 

Public Attributes

data
 Data stored in this Node. More...
 
std::unique_ptr< Node< T > > left
 Left child of this Node.
 
std::unique_ptr< Node< T > > right
 Right child of this Node.
 
Node< T > * parent
 Parent of this Node.
 

Detailed Description

template<typename T>
struct APutils::Node< T >

Class that implements a node of a tree.

General class that can be used in any tree, for example it could be used in a class bt that implements a Binary Tree (and then APbst::bst could inherit from bt).

Constructor & Destructor Documentation

◆ Node() [1/3]

template<typename T>
APutils::Node< T >::Node ( )
inlinenoexcept

Void constructor.

Used only to create a void root Node when an object APbst::bst is instantiated.

◆ Node() [2/3]

template<typename T>
APutils::Node< T >::Node ( const T &  data,
Node< T > *  parent 
)
inlinenoexcept

Copy constructor with data.

Parameters
dataThe values to be stored in the Node.
parentRaw pointer to the parent Node of this Node.

To create a Node with given data and parent, and left and right initialized to nullptr.

◆ Node() [3/3]

template<typename T>
APutils::Node< T >::Node ( T &&  data,
Node< T > *  parent 
)
inlinenoexcept

Move constructor with data.

Parameters
dataThe values to be stored in the Node.
parentRaw pointer to the parent Node of this Node.

To create a Node with given data and parent, and left and right initialized to nullptr.

Member Function Documentation

◆ printNode() [1/2]

template<typename T>
void APutils::Node< T >::printNode ( std::ostream &  os,
const bool &  printChildren 
)
inline

Utility function that prints a Node.

Parameters
osThe stream to which you'd like to print the Node.
printChildrenWhether to print the children of each node as well.

Prints the content of the Node: the data, the left child and the right child.

◆ printNode() [2/2]

template<typename T>
void APutils::Node< T >::printNode ( )
inline

Utility function that prints a Node.

Overloaded printNode() that prints, without arguments, each node and their children to std::cout.

Member Data Documentation

◆ data

template<typename T>
T APutils::Node< T >::data

Data stored in this Node.

E.g. for a APbst::bst std::pair<const Key,Value>, where Key is the key of this Node and Value is the value stored in this Node.


The documentation for this struct was generated from the following file: