小杨想在如上题所述的双向链表中加入一首新歌曲。为了能快速找到该歌曲,他将其作为链表的第一首歌 曲,则下面横线上应填入的代码为( )。
void insert(dl_node *head, string my_song) {
p = new dl_node;
p->song = my_song;
p->prev = nullptr;
p->next = head;
if (head != nullptr) {
________________________________ // 在此处填入代码
}
head = p;
}
- A. head->next->prev = p;
- B. head->next = p;
- C. head->prev = p;
- D. 触发异常,不能对空指针进行操作。
正确答案:C