-1
我嘗試訪問以前的某個不是結構或聯合的代碼: * head-> previous = newHead將我的鏈接列表轉換爲雙向鏈接列表,但在訪問上一個插入頭時遇到問題
我不太確定爲什麼...任何幫助非常感謝。
`
struct ListNode
{
int value;
struct ListNode* next;
struct ListNode* previous;
};
void insertAtHead(struct ListNode** head,int val)
{
struct ListNode* newHead = malloc(sizeof(struct ListNode));
newHead->value = val;
newHead->next = NULL;
newHead->previous = NULL;
if(*head == NULL)
*head = newHead;
else
{
newHead->next = *head;
*head->previous = newHead;
*head = newHead;
}
}`
嘗試'(* head) - > previous' – WhozCraig