我一直在尝试递归中编写一个分类的链接列表函数

I have been trying to write a sorted linked list function in c++ recursively

本文关键字:分类 一个 链接 函数 列表 递归 我一直在      更新时间:2023-10-16

我一直在尝试递归编写一个分类的链接列表函数。任何人都可以帮我吗?我什么都没到任何功能。

void LinkedList::insertRecurcive(Node* head, int data)
{
if (head == NULL || !(head->Data < data ) )
    {
        head->next = new Node;``
        head->next->Data = data;
        head->next->next = NULL; 
    }
    else
    insertRecurcive( head->next, data );

}
void LinkedList::insert(int data)
{
    insertRecurcive(head, data);
}

您的代码:

if (head == NULL || !(head->Data < data ) )
    {    
        head->next = new Node;``
head->next->Data = data;
head->next->next = NULL;
}

即使头为null,也将分配给头 ->即使这将失败。