第 4 题
假设有一个链表的节点定义如下:
struct Node { int data; Node* next; }
现在有一个指向链表头部的指针:Node* head。如果想要在链表中插入一个新节点,其成员 data 的值为 4242,并使新节点成为链表的第一个节点,下面哪个操作是正确的?
A.
Node* newNode = new Node; newNode->data = 42; newNode->next = head; head = newNode;
B.
Node* newNode = new Node; head->data = 42; newNode->next = head; head = newNode;
C.
Node* newNode = new Node; newNode->data = 42; head->next = newNode;
D.
Node* newNode = new Node; newNode->data = 42; newNode->next = head;