Last active
July 20, 2024 15:21
-
-
Save colorbox/1bedc16a0bb2a88b79415f464d6e86dd to your computer and use it in GitHub Desktop.
https://leetcode.com/problems/reverse-linked-list/ にて、なぜかエラーになる。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
下記のようなエラーが出る。 | |
``` | |
Line 173: Char 16: runtime error: reference binding to misaligned address 0xbebebebebebec0b6 for type 'ListNode *', which requires 8 byte alignment (stl_deque.h) | |
0xbebebebebebec0b6: note: pointer points here | |
<memory cannot be printed> | |
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/stl_deque.h:182:16 | |
``` | |
*/ | |
class Solution { | |
public: | |
ListNode* reverseList(ListNode* head) { | |
stack<ListNode*> stack; | |
while (head) { | |
ListNode* preserved_next = head->next; | |
head->next = nullptr; | |
if (!stack.empty()) { | |
head->next = stack.top(); | |
} | |
stack.push(head); | |
head = preserved_next; | |
} | |
return stack.top(); | |
ListNode* hoge = new ListNode(stack.top()->val, stack.top()->next); | |
while (!stack.empty()) { | |
stack.pop(); | |
} | |
return hoge; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment