I'm working on building understanding of data structures in general, and specifically linked lists in this example. I'm also trying to increase my ability with templates.
In cross-referencing dozens of examples, I've blended what I've seen into the following node template "Node.h" file:
/*
11 May 2015
VS 2015 Community
Author: Diche Bach
Node template header file.
*/
#ifndef NODE_H
#define NODE_H
#include<iostream>
template<class tNode>
class Node
{
friend std::istream& operator>>(std::istream& str, tNode& data)
{
return str >> data_;
}
friend std::ostream& operator<<(std::ostream& str, tNode const& data)
{
return str << data_ << " ";
}
public:
Node(tNode data, tNode *link);
private:
tNode data;
tNode *next;
};
#endif /* NODE_H */
The goal is that this Node template be as modular and 'resusable' as possible. Thus, the same node template could be used with a LinkedList template, a DoubleLinked List template, a Stack template, etc.
With only two semesters of C++ under my belt, I'm pushing my envelope, and I appreciate suggestions and comments.
The use of the friend mechanism is something I've never done before, but it seems salient to the goals, so I particularly appreciate comments on that portion.