Ash*_*Ash 1 c++ linked-list list
以下哪一项是将第一个对象存储在链表中的更正确的方法?或者有人可以指出每个的优点/缺点.谢谢.
class Node
{
int var;
Node *next;
static Node *first;
Node()
{
if (first == NULL)
{
first = this;
next = NULL;
}
else
//next code here
}
}
}
Node* Node::first = NULL;
new Node();
Run Code Online (Sandbox Code Playgroud)
- 要么 -
class Node
{
int var;
Node *next;
Node()
{
//next code here
}
}
Node* first = new Node();
Run Code Online (Sandbox Code Playgroud)