TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
Loading...
Searching...
No Matches
node.hpp File Reference

Provides Node class and related utilities. More...

#include <iostream>
#include <memory>
#include <vector>
Include dependency graph for node.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  Node< ValueType >
 

Functions

template<typename Node , typename Action >
void traverse (const Node *const inNode, const Action &action)
 
template<typename Node >
void display_all (const Node *const inNode)
 
template<typename Node >
std::vector< typename Node::value_type > push_all_to_vector (const Node *const inNode, const std::size_t expected_size=0)
 

Detailed Description

Provides Node class and related utilities.

Definition in file node.hpp.

Function Documentation

◆ display_all()

template<typename Node >
void display_all ( const Node *const inNode)

Definition at line 31 of file node.hpp.

31 {
32 traverse(inNode,
33 [](const Node& curNode) { std::cout << curNode.data << " "; });
34}

◆ push_all_to_vector()

template<typename Node >
std::vector< typename Node::value_type > push_all_to_vector ( const Node *const inNode,
const std::size_t expected_size = 0 )

Definition at line 37 of file node.hpp.

38 {
39 std::vector<typename Node::value_type> res;
40 res.reserve(expected_size);
41 traverse(inNode,
42 [&res](const Node& curNode) { res.push_back(curNode.data); });
43 return res;
44}

◆ traverse()

template<typename Node , typename Action >
void traverse ( const Node *const inNode,
const Action & action )

Definition at line 23 of file node.hpp.

23 {
24 if (inNode) {
25 action(*inNode);
26 traverse(inNode->next.get(), action);
27 }
28}