【发布时间】:2012-12-21 19:58:42
【问题描述】:
这里关于指针的使用有一件事我不明白Cell *curr = head;这里取head的地址,它用它做什么?
Cell *ConvertToListIter(Vector<int>& vector)
{
Cell *head = new Cell;
head->next = NULL;
head->value = vector[0];
Cell *curr = head;
for (int i = 1; i < vector.size(); i++) {
Cell *newCell = new Cell;
newCell->next = NULL;
newCell->value = vector[i];
curr->next = newCell;
newCell = curr;
}
return head;
}
【问题讨论】:
-
curr始终是指向列表中最后一个元素的指针,因此您可以轻松追加新节点。 -
@DanielFischer,或者至少应该是......这段代码中有一个错误。
-
@MarkRansom 当我扫视时它并不存在。真相。
标签: c++ pointers linked-list