Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

stdtree

stdtree is a small C++20 tree library that provides a TreeNode implementation plus a TreeView wrapper for building, traversing, and printing tree structures.

Features

  • Create tree nodes with values, depth, and index metadata
  • Add child nodes and navigate siblings/parents
  • Inspect descendants, paths, and subtree contents
  • Print trees in an ASCII-style layout with printTree()
  • Build and test with CMake and CTest

Project layout

  • stdtree.hpp — public umbrella header for TreeView
  • treenode.hppTreeNode implementation
  • main.cpp — example program that builds and prints a sample tree
  • tests/stdtree_tests.cpp — unit tests
  • CMakeLists.txt — build and test configuration

Build

From the project root:

cmake -S . -B build
cmake --build build

Run the example

./build/stdtree

Example output:

└──(0, 0)
   ├──(1, 1)
   │  ├──(3, 3)
   │  └──(4, 4)
   └──(2, 2)
      ├──(5, 5)
      │  ├──(7, 7)
      │  └──(8, 8)
      └──(6, 6)

Run tests

ctest --test-dir build --output-on-failure

Requirements

  • C++20 compiler
  • CMake 3.10 or newer

Example source

#include <iostream>
#include <memory>
#include <utility>

#include "stdtree.hpp"


struct Geo2D
{
    double x;
    double y;

    Geo2D(double x, double y) : x(x), y(y) {}

    friend std::ostream& operator<<(std::ostream& os, const Geo2D& geo)
    {
        os << "(" << geo.x << ", " << geo.y << ")";
        return os;
    }
};


int main()
{
    TreeView<Geo2D, std::size_t> tree(std::make_unique<TreeNode<Geo2D, std::size_t>>(Geo2D(0, 0), 0, 0));

    tree.getRoot()->addChild(Geo2D(1, 1));
    tree.getRoot()->addChild(Geo2D(2, 2));
    tree.getRoot()->getChild(0)->addChild(Geo2D(3, 3));
    tree.getRoot()->getChild(0)->addChild(Geo2D(4, 4));
    tree.getRoot()->getChild(1)->addChild(Geo2D(5, 5));
    tree.getRoot()->getChild(1)->addChild(Geo2D(6, 6));
    tree.getRoot()->getChild(1)->getChild(0)->addChild(Geo2D(7, 7));
    tree.getRoot()->getChild(1)->getChild(0)->addChild(Geo2D(8, 8));

    tree.printTree();
    
    return 0;
}

About

small C++20 tree library that provides a TreeNode implementation plus a TreeView wrapper for building, traversing, and printing tree structures.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages