好的,所以我设置了一个链接列表结构:
struct ListNode {
ListNode* next;
int data;
ListNode(int in) {
data = in;
next = NULL;
}
ListNode(int in, ListNode* n) {
data = in;
next = n;
}
};
连同插入功能:
bool insertNode(ListNode **head, int position, int data) {
if (position == 0) {
ListNode *element = new ListNode(data, *head->next);
*head->next = element;
return true;
}
else if (head == NULL)
return false;
else {
insertNode(head->next, position-1, data);
}
}
我将如何访问 head 的下一个元素?使用当前的代码,我收到以下错误消息:
request for member ‘next’ in ‘* head’, which is of non-class type ‘ListNode*’