【发布时间】:2014-07-26 18:20:39
【问题描述】:
我对我在大学看到的这段代码有疑问。
struct nodeList{
int data;
nodeList * next;
};
typedef nodeList * List;
void filter( List &l )
{
List * aux = &l;
while(*aux)
{
if( (*aux)->data > 3 )
{
List toDelete = *aux;
*aux = (*aux)->next;
delete toDelete;
}
else
{
aux = &((*aux)->next);
}
}
}
我不知道,
List * aux = &l;实际上是做什么的。因为List与nodeList *相同,所以代码将是nodeList * * aux = &l;,这实际上是我不明白的,是指向包含nodeList struct指针地址的指针的指针?我无法理解的第二件事是最后一行。
aux = &((*aux)->next);为什么aux左侧没有*?如果它被声明为List *aux = &l;是List只是指向第一个节点的指针?
提前谢谢你。我google了很多,但我没有找到任何答案。如果您能回答我的问题,我将不胜感激。
【问题讨论】:
-
也许这行:
typedef nodeList * List;本来应该写成typedef nodeList List;然后很多事情似乎可以理解。 -
不,那一行是*我输入的,它可以工作。去掉高于 3 的值