-1

在这行代码中尝试访问不是结构或联合的“previous”时出现错误错误:*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;
     } 
}`
4

1 回答 1

0

->运算符的优先级高于*。因此, *head->previous被分组为*(head->previous),这不是您想要的。使用括号:

(*head)->previous = newHead;
于 2013-04-16T05:24:49.747 回答