0
좋아 액세스해야하는, 그래서 링크 된 목록을 수 있도록 설정 구조체 한 구조체 :C++ LinkedList의 더블 포인터로 참조하고 다음 노드에게
삽입 기능과 함께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);
}
}
어떻게 머리의 다음 요소에 액세스 할 수 있습니까?
request for member ‘next’ in ‘* head’, which is of non-class type ‘ListNode*’
성공에 대해 현재 위치에있는 코드로,이 오류 메시지가 나타납니다! 신속한 응답에 감사드립니다! – AdamMurderface
너무 빨리 말하십시오. 그것은 처음 두 head-> 다음 호출에 대해 작동하지만, 재귀 호출을 전달할 때, 그것을 좋아하지 않는다 : 'ListNode *'를 'ListNode **'인수로 '1'을 'bool'로 변환 할 수 없다. insertNode (ListNode **, int, int) ' – AdamMurderface
오오, 나는 전체 코드를 읽지 못했습니다. 그것은 단지 & 헤드 -> 다음입니다 – ablm