尝试访问此行代码中的结构或联合内容中的“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;
}
}`
答案 0 :(得分:0)
->
运算符的higher precedence大于*
。所以,
*head->previous
被归为*(head->previous)
,这不是您想要的。使用括号:
(*head)->previous = newHead;