SleakEngine 1.0.0
C++23 multi-backend game engine
Loading...
Searching...
No Matches
Sleak::Tree< T > Class Template Reference

Implements a binary tree data structure for hierarchical data organization. More...

#include <Tree.hpp>

Public Member Functions

 Tree ()
 ~Tree ()
 Deletes every node in the tree.
void clear ()
 Removes every node, leaving an empty tree.
bool contains (const T &value)
 True if value exists anywhere in the tree.
bool contains (Node *node, const T &value)
 True if value exists in the subtree rooted at node.
void inOrder ()
 Traverses the tree in-order (left, node, right).
void insert (const T &value)
 Inserts value, keeping BST ordering (duplicates go right).
void remove (const T &value)
 Removes value from the tree, if present.

Detailed Description

template<typename T>
class Sleak::Tree< T >

Implements a binary tree data structure for hierarchical data organization.

The BinaryTree class organizes data in a hierarchical manner with nodes and edges, where each node has at most two children. It is suitable for scenarios where you need to represent hierarchical relationships, such as file systems, decision trees, or expression trees. Use this class when you need to implement tree-based algorithms, search trees, or hierarchical data storage.

Example Use Cases:

  • Representing a file system directory structure.
  • Implementing decision trees in machine learning.
  • Storing and evaluating arithmetic expressions.
  • Implementing binary search trees for efficient searching.

Implementation Details:

  • Uses a tree node structure with pointers to left and right children.
  • Provides methods for inserting, searching, and traversing nodes.
  • Supports various tree traversal algorithms (e.g., in-order, pre-order, post-order).

Definition at line 29 of file Tree.hpp.

Constructor & Destructor Documentation

◆ Tree()

template<typename T>
Sleak::Tree< T >::Tree ( )
inline

Definition at line 119 of file Tree.hpp.

◆ ~Tree()

template<typename T>
Sleak::Tree< T >::~Tree ( )
inline

Deletes every node in the tree.

Definition at line 122 of file Tree.hpp.

Member Function Documentation

◆ clear()

template<typename T>
void Sleak::Tree< T >::clear ( )
inline

Removes every node, leaving an empty tree.

Definition at line 156 of file Tree.hpp.

◆ contains() [1/2]

template<typename T>
bool Sleak::Tree< T >::contains ( const T & value)
inline

True if value exists anywhere in the tree.

Definition at line 150 of file Tree.hpp.

◆ contains() [2/2]

template<typename T>
bool Sleak::Tree< T >::contains ( Node * node,
const T & value )
inline

True if value exists in the subtree rooted at node.

Definition at line 140 of file Tree.hpp.

◆ inOrder()

template<typename T>
void Sleak::Tree< T >::inOrder ( )
inline

Traverses the tree in-order (left, node, right).

Definition at line 163 of file Tree.hpp.

◆ insert()

template<typename T>
void Sleak::Tree< T >::insert ( const T & value)
inline

Inserts value, keeping BST ordering (duplicates go right).

Definition at line 128 of file Tree.hpp.

◆ remove()

template<typename T>
void Sleak::Tree< T >::remove ( const T & value)
inline

Removes value from the tree, if present.

Definition at line 134 of file Tree.hpp.