我必须在同一个函数中重用这段代码,但它不起作用,因为res1->nextPtr已经在链表的末尾。有没有办法将其重置为链表的"头部"?
do
{
res1 = res1->nextPtr;
}while(res1 != NULL);
LIST *head = res1;
LIST *list = head;
while (list) {
//do something
list = list->nextPtr;
};
list= head;
//again traverse over list
如果您的 res1 为空,则您的 do-while 将出现段错误。