Friday, 6 September 2013

C++ class design "helper functions"

C++ class design "helper functions"

I have created a basic class that creates an adjacency list (graph
theory). I have coded a depth first search function but it is of poor
design and is currently 50 lines long. I am trying to reduce the size and
improve readability of the function.
template <class T>
class adj_list
{
public:
void add_node (const T data);
void add_edge(const T first, const T second);
void remove_node (const T data);
void remove_edge(const T first, const T second);
void dfs(const T node, const T lookfor);
void print_list() const;
private:
std::map<T, std::set<T>> graph;
};
So I will need to have 2-3 "helper" (not sure what to call these)
functions which do specific things in the dfs algorithm. They will have to
read the private graph, but not modify it.
Is my best option to just add these new smaller functions as public
members? I don't think that I want a user to be using these functions.
What is the best way to go about this?

No comments:

Post a Comment