我正在尝试为学习经验创建自己的双链表。我的书显示了下面的节点结构,我想知道这是否等同于我创建的节点类?结构中的该函数是否只是一种构造函数,为结构中的每种数据类型分配值?
//===== Struct =====
struct Node
{
Node *next;
Node *prev;
std::string val;
Node(const std::string &value, Node *nextVal = NULL, Node *prevVal = NULL) :
val(value), next(nextVal), prev(prevVal) {}
};
//===== Class ====
class Node
{
public:
Node(std::string value = "", Node *pVal = NULL, Node *nVal = NULL);
virtual ~Node(void);
protected:
Node *next;
Node *prev;
std::string val;
};
Node(std::string value = "", Node *pVal = NULL, Node *nVal = NULL)
{
next = nVal;
prev = pVal;
val = value;
}