From ef31885f61459b7a88a003891aa03c678a2fe100 Mon Sep 17 00:00:00 2001 From: Dominik Meyer Date: Tue, 4 Jun 2019 10:55:28 +0200 Subject: [PATCH] ADD: return the root of the tree --- include/Tree/tree.hpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/Tree/tree.hpp b/include/Tree/tree.hpp index a3f308a..ca16f78 100644 --- a/include/Tree/tree.hpp +++ b/include/Tree/tree.hpp @@ -52,6 +52,22 @@ namespace Tree std::list> children; public: + + /** + * @brief get the root of the tree + * + */ + std::shared_ptr getRoot() + { + if (parent==nullptr) + { + return shared_from_this(); + } + + return parent->getRoot(); + + } + /** * @brief print the tree starting with the current node to stdout *