【发布时间】:2017-04-19 03:52:19
【问题描述】:
我只是有一个关于如何打印队列中最后一个元素的快速问题。这是我目前所拥有的:
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.
谢谢!
【问题讨论】:
-
如果您尚未使用该循环打印所有元素,则必须断开链接。