-1
我只是有一個關於如何打印隊列中最後一個元素的快速問題。這是我到目前爲止:用尾指針打印節點的鍵
struct queue {
node * head;
node * tail;
};
void printQ(queue & q) {
node * p = q.head;
cout << "QUEUE: ";
if (q.head == NULL)
cout << "empty";
while (p != NULL)
{
cout << p->key << " ";
p = p->next;
}
cout << " TAIL=" << ?????? // This is where I would like to
get it to print the tail but I'm not
sure how.
謝謝!
如果您尚未打印所有具有該循環的元素,則必須斷開您的鏈接。 – molbdnilo