(1) 考輸出,主要是 ++a+b++ 如何解讀? -> (++a) + (b++)
(2) toggle_bit(int x, int bit) 實作
(3) is_even(int x) 實作
(4) is_little_endian() 實作
(5) Node* remove_if(Node *head, bool (*remove_fn)(Node *node)) 實作
{
// create a dummy node that points to the original head
Node dummy;
dummy.next = head;
// prev always points to the last node that is kept
Node *prev = &dummy;
// cur scans through the list
Node *cur = head;
while (cur != NULL) {
if (remove_fn(cur)) {
// unlink cur: remove it from the list
prev->next = cur->next;
// free the removed node
free(cur);
// move cur to the next node after prev
cur = prev->next;
} else {
// keep cur: advance both prev and cur
prev = cur;
cur = cur->next;
}
}
// new head might have changed
return dummy.next;
}