さて、リンクリスト構造体を次のように設定しました。
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*’