KOB*_*KOB -3 c++ recursion linked-list
我正在编写一个涉及链表的程序.我编写了一个函数,它返回链表中的第n个节点,它以递归方式调用自身.我的程序编译并运行直到递归函数然后崩溃.这是节点的构造函数以及递归函数:
LinkedList::LinkedList():
head(head){
sizeInt = 0;
}
Node* LinkedList::get_nth(const int& n) const {
Node* node = new Node();
for(int counter = 1; counter <= n; counter++){
node = get_nth(counter + 1);
}
return node;
}
Run Code Online (Sandbox Code Playgroud)
这个功能有什么问题?如果您需要更多详细信息或代码,请告诉我们.
| 归档时间: |
|
| 查看次数: |
557 次 |
| 最近记录: |