我正在编写一个涉及链表的程序。我写了一个函数,它返回链表中的第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;
}
这个函数有什么问题?让我知道你是否需要更多的细节或代码。
'n'有多大? – NathanOliver
到目前为止,它仅仅是最大的10 – KOB
崩溃如何?什么是错误信息? –