Possible Duplicate:
Reversing Linked List - C++
自周一以来,我一直在做家庭作业,但我仍然找不到我的反向列表函数未返回反向节点的原因。我检查了,仔细检查,甚至三重检查,但仍然。任何帮助将不胜感激。我在Vista上使用dec-C ++。这是我的功能:List::ListNode *List::Reverse_List(ListNode *head) { ListNode* result = NULL; ListNode* cur = head; ListNode* next; while (cur != NULL) { next = cur->next; cur->next = result; //move the node into result result = cur; cur = next; } head = result; return result; }
最佳答案
尝试用铅笔在纸上绘图,您的堆内部正在发生什么。然后,您将了解如何改进代码。
并且以更特定于C ++的方式,您可以使用std::list<>
或std::vector<>
之类的模板化集合
关于c++ - C++中的我的反向列表功能不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7908822/