如何在C++; 在java中有一个答案,但是寻找一些应用于C++的东西。这段代码可以工作(有点),但会进入一个无限循环。任何建议都将不胜感激 void mirror(ListType & list) { ListType listMirror = NULL; Node *p = list; listMirror = p; listMirror->next = NULL; Node *q = listMirror; while (list->next != NULL){ p = p->next; listMirror = p; q = listMirror->next; p->next; if (p = q)(list->next = NULL); } list->next = listMirror; }
列表的类型为“ListType”,而p的类型为“Node”,这会导致while循环上出现未定义的行为(因为它显然是编译的) 改变这个如何在C++; 在java中有一个答案,但是寻找一些应用于C++的东西。这段代码可以工作(有点),但会进入一个无限循环。任何建议都将不胜感激 void mirror(ListType & list) { ListType listMirror = NULL; Node *p = list; listMirror = p; listMirror->next = NULL; Node *q = listMirror; while (list->next != NULL){ p = p->next; listMirror = p; q = listMirror->next; p->next; if (p = q)(list->next = NULL); } list->next = listMirror; },c++,linked-list,mirror,C++,Linked List,Mirror,列表的类型为“ListType”,而p的类型为“Node”,这会导致while循环上出现未定义的行为(因为它显然是编译的) 改变这个 Node *p = list; 指向列表中的第一个成员 Node *p = list.firstMemeber()//this is an example, refer to your documentation 旁注:使用nullptr。NULL已经过时了。也许只有我一个人,但阅读这些代码会让人感到困惑和痛苦。你认为下一步是什么在做什么?对不起,应该
Node *p = list;
指向列表中的第一个成员
Node *p = list.firstMemeber()//this is an example, refer to your documentation
旁注:使用nullptr。NULL已经过时了。也许只有我一个人,但阅读这些代码会让人感到困惑和痛苦。你认为下一步是什么代码>在做什么?对不起,应该提到“ListType”等同于“typedef节点*ListType”。
Node *p = list.firstMemeber()//this is an example, refer to your documentation