我一直在尝试递归中编写一个分类的链接列表函数
I have been trying to write a sorted linked list function in c++ recursively
我一直在尝试递归编写一个分类的链接列表函数。任何人都可以帮我吗?我什么都没到任何功能。
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,也将分配给头 ->即使这将失败。
相关文章:
- 如何创建一个CMake变量,除非显式重写,否则使用默认值
- 删除一个线程上有数百万个字符串的大型哈希映射会影响另一个线程的性能
- 为什么两个不同的未命名名称空间可以共存于一个cpp文件中
- 运行同一解决方案的另一个项目的项目
- 挂起和取消挂起一个文件DLL
- 用C++中的一个变量定义一个常量
- 函数向量_指针有不同的原型,我可以构建一个吗
- 为我的 c++ 类介绍制作一个三角形分类器.我有几个问题
- 为什么std :: map中有一个分类机制
- 我一直在尝试递归中编写一个分类的链接列表函数
- 如何插入一个分类的单链接列表中
- 使用lambda函数将向量与另一个向量进行分类
- 从其他两个文件中创建一个分类整数的文件
- 分类一个向量,该向量由该类中的成员字符串保存对象
- 根据没有类或结构的另一个向量的元素对一个向量进行分类
- 基于另一个分类向量对向量进行分类
- 做一个CPP分类的元组
- 在其他班级成员的向量中找到一个分类记录
- 需要一个好的算法来对8GB的图片进行分类
- 如何使用多个 SVM 分类器(每个分类器都有一个特定的内核)作为"one vs rest classification"方案?