赞
踩
总结一下在做leetcode第二题两数之和时遇到的问题。
问题一:
在leetcode中如何实现尾插,在尾插定义新节点时总会报如下错误:
runtime error: member access within null pointer of type 'struct ListNode' [solution.c]
这是使用了空指针,其实是没有给指针申请空间。
- struct ListNode* tail=NULL;
- tail = malloc(sizeof(struct ListNode)); //如果没有此句会报错
问题二:
在解决问题一后运行代码依旧会报如下错误:
Line 70: Char 15: runtime error: member access within misaligned address 0xbebebebebebebebe for type 'struct ListNode', which requires 8 byte alignment [ListNode.c] 0xbebebebebebebebe: note: pointer points here <memory cannot be printed>
这是指针的*next没有赋值NULL,记得添加:
tail->next = NULL;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。