/** * @file * @brief Provides Node class and related utilities **/ #ifndef DATA_STRUCTURES_NODE_HPP_ #define DATA_STRUCTURES_NODE_HPP_ #include /// for std::cout #include /// for std::shared_ptr #include /// for std::vector /** Definition of the node as a linked-list * \tparam ValueType type of data nodes of the linked list should contain */ template struct Node { using value_type = ValueType; ValueType data = {}; std::shared_ptr> next = {}; }; template void traverse(const Node* const inNode, const Action& action) { if (inNode) { action(*inNode); traverse(inNode->next.get(), action); } } template void display_all(const Node* const inNode) { traverse(inNode, [](const Node& curNode) { std::cout << curNode.data << " "; }); } template std::vector push_all_to_vector( const Node* const inNode, const std::size_t expected_size = 0) { std::vector res; res.reserve(expected_size); traverse(inNode, [&res](const Node& curNode) { res.push_back(curNode.data); }); return res; } #endif // DATA_STRUCTURES_NODE_HPP_