資料結構›Ch4 鏈結串列第 12 題/共 22 題
12. Queue、Linked List、C++
#DS-04-012易QueueLinked ListC++
題組題幹(本題:②,共 3 小題)點擊展開
The following contains the C++ code for a queue implemented with a singly linked list.
struct Qnode
{
int key;
Qnode * next;
Qnode(int n = 0) : key(n), next(NULL) {}
};
struct Qlist
{
Qnode * head, * tail;
Qlist() : head(NULL), tail(NULL) {}
void push(int n)
{
Qnode* node = new Qnode(n);
if (!head) ① = node;
if (tail) ② = node;
tail = ③ ;
}
void pop()
{
if (head) {
Qnode* node = ④ ;
⑤ = ⑥ ;
delete node;
}
if (!head) tail = NULL;
}
};
Which way of filling in the code will make the pop function work correctly?
📄 交大113
▤完整推導請見《WH 資工筆記 · 資料結構》Ch4 鏈結串列