資料結構›Ch4 鏈結串列
第 13 題/共 22 題
◀ DS 13/22
13. Queue、Linked List、C++
#DS-04-013易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;
    }
};

Based on the code above, given the following statements, what are the key values of the two nodes pointed to by head and tail?

Qlist L = Qlist();
L.pop();  L.push(10);  L.push(5);  L.push(3);  L.pop();
L.push(12);  L.push(8);  L.pop();
📄 交大113
跳轉到第題
▤完整推導請見《WH 資工筆記 · 資料結構》Ch4 鏈結串列
本章題號 · 1–20 / 22