資料結構›Ch4 鏈結串列
第 11 題/共 22 題
◀ DS 11/22
11. Queue、Linked List、C++
#DS-04-011易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 push function work correctly?

📄 交大113
跳轉到第題
▤完整推導請見《WH 資工筆記 · 資料結構》Ch4 鏈結串列
本章題號 · 1–20 / 22