Data Structures & Algorithms in C++
Goodrich, Tamassia, Mount and Goldwasser
Loading...
Searching...
No Matches
Data Structures | Public Member Functions | Protected Attributes
dsac::tree::LinkedBinaryTree< E > Class Template Reference

#include <linked_binary_tree.h>

Inheritance diagram for dsac::tree::LinkedBinaryTree< E >:
Inheritance graph
Collaboration diagram for dsac::tree::LinkedBinaryTree< E >:
Collaboration graph

Data Structures

class  Node
 
class  Position
 

Public Member Functions

 LinkedBinaryTree ()
 Constructs a tree storing zero elements.
 
int size () const
 Returns the number of elements stored in the tree.
 
bool empty () const
 Returns true if the tree does not have any elements.
 
Position root () const
 Returns a Position for the root (a null Position, if an empty tree)
 
std::vector< Positionpositions () const
 Returns an inorder sequence of positions.
 
void add_root (const E &e=E())
 Creates a root for an empty tree, storing e as the element; should never be called on non-empty tree.
 
void add_left (Position p, const E &e)
 
void add_right (Position p, const E &e)
 
void erase (Position p)
 
void attach (Position p, LinkedBinaryTree &left, LinkedBinaryTree &right)
 
 ~LinkedBinaryTree ()
 
 LinkedBinaryTree (const LinkedBinaryTree &other)
 
LinkedBinaryTreeoperator= (const LinkedBinaryTree &other)
 
 LinkedBinaryTree (LinkedBinaryTree &&other)
 
LinkedBinaryTreeoperator= (LinkedBinaryTree &&other)
 

Protected Attributes

Nodert {nullptr}
 
int sz {0}
 

Constructor & Destructor Documentation

◆ LinkedBinaryTree() [1/3]

template<typename E >
dsac::tree::LinkedBinaryTree< E >::LinkedBinaryTree ( )
inline

Constructs a tree storing zero elements.

◆ ~LinkedBinaryTree()

template<typename E >
dsac::tree::LinkedBinaryTree< E >::~LinkedBinaryTree ( )
inline

◆ LinkedBinaryTree() [2/3]

template<typename E >
dsac::tree::LinkedBinaryTree< E >::LinkedBinaryTree ( const LinkedBinaryTree< E > &  other)
inline

◆ LinkedBinaryTree() [3/3]

template<typename E >
dsac::tree::LinkedBinaryTree< E >::LinkedBinaryTree ( LinkedBinaryTree< E > &&  other)
inline

Member Function Documentation

◆ add_left()

template<typename E >
void dsac::tree::LinkedBinaryTree< E >::add_left ( Position  p,
const E &  e 
)
inline

Creates a new node storing element e, and links the new node as the left child of position p. Should not be called if p already has a (non-null) left child.

◆ add_right()

template<typename E >
void dsac::tree::LinkedBinaryTree< E >::add_right ( Position  p,
const E &  e 
)
inline

Creates a new node storing element e, and links the new node as the right child of position p. Should not be called if p already has a (non-null) right child.

◆ add_root()

template<typename E >
void dsac::tree::LinkedBinaryTree< E >::add_root ( const E &  e = E())
inline

Creates a root for an empty tree, storing e as the element; should never be called on non-empty tree.

◆ attach()

template<typename E >
void dsac::tree::LinkedBinaryTree< E >::attach ( Position  p,
LinkedBinaryTree< E > &  left,
LinkedBinaryTree< E > &  right 
)
inline

Attaches the internal structures of trees left and right and subtrees of leaf p, and resets left and right to empty trees. Should not be called on non-leaf p.

◆ empty()

template<typename E >
bool dsac::tree::LinkedBinaryTree< E >::empty ( ) const
inline

Returns true if the tree does not have any elements.

◆ erase()

template<typename E >
void dsac::tree::LinkedBinaryTree< E >::erase ( Position  p)
inline

Removes the node (and element) at position p, replacing the node with its one child, if any. Should not be called on a node with two children.

◆ operator=() [1/2]

template<typename E >
LinkedBinaryTree & dsac::tree::LinkedBinaryTree< E >::operator= ( const LinkedBinaryTree< E > &  other)
inline

◆ operator=() [2/2]

template<typename E >
LinkedBinaryTree & dsac::tree::LinkedBinaryTree< E >::operator= ( LinkedBinaryTree< E > &&  other)
inline

◆ positions()

template<typename E >
std::vector< Position > dsac::tree::LinkedBinaryTree< E >::positions ( ) const
inline

Returns an inorder sequence of positions.

Here is the call graph for this function:

◆ root()

template<typename E >
Position dsac::tree::LinkedBinaryTree< E >::root ( ) const
inline

Returns a Position for the root (a null Position, if an empty tree)

◆ size()

template<typename E >
int dsac::tree::LinkedBinaryTree< E >::size ( ) const
inline

Returns the number of elements stored in the tree.

Field Documentation

◆ rt

template<typename E >
Node* dsac::tree::LinkedBinaryTree< E >::rt {nullptr}
protected

◆ sz

template<typename E >
int dsac::tree::LinkedBinaryTree< E >::sz {0}
protected

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