如何合并两个双重链接列表(访问下一个链接)
How to merge two Doubly Linked Lists (Accessing next link)
我正在尝试合并两个双重链接列表。我已经创建了一个函数,可以按正确的顺序插入新节点。这些参数是由我的教授设定的,因此我无法更改它们。我能够将第一个项目添加到List1,但无法再添加。
我在尝试继续浏览List2并在List1中添加更多项目时会遇到错误。我尝试了递归和循环时做一个。在尝试使用do-while循环
时struct nodeType{
int info;
nodeType *next;
nodeType *back;
};
class OrderedDoublyLinkedList{
public:
//Insert x in appropriate place in the list to keep it
sorted
void insertNode(int x);
void mergeLists(OrderedDoublyLinkedList &List1,
OrderedDoublyLinkedList &List2);
private:
int count;
nodeType *first;
nodeType *last;
};
void
OrderedDoublyLinkedList::mergeLists(OrderedDoublyLinkedList
&List1, OrderedDoublyLinkedList &List2){
//First Technique
do{
List1.insertNode(List2.first->info);
List2.first->next; //Error: Expresion result unused
}
while(List2.first!=NULL)
//Second Technique
while(List2.first!=NULL)
List1.insertNode(List2.first->info);
mergeLists(&List1, &List2.first->next);
//If I try to use this it says cannot bind to a temporary of
type
我需要帮助访问下一个节点将其余信息添加到List1。
看起来很简单,而循环就是您所需要的
nodeType* n = List2.first;
while (n != NULL)
{
List1.insertNode(n->info);
n = n->next;
}
尽管我仍然担心这是否是可以接受的解决方案。您说您需要将 List2
移动到List1
中,这不是此代码所做的,此代码 copies List2
to List1
,List2
不受此代码的影响。
相关文章:
- 链接器找不到在虚拟类 c++ 中访问的静态字段的符号
- 在单元测试项目中包括 .c 文件,并从多个 cpp 文件访问它而不会出现链接问题
- 链接 boost 库时"Error while loading shared libraries"引发的,除了我无法使用 root 访问权限来修复它
- 在链接的程序集文件中,我想从 c++ 调用代码访问变量.是否可以在不触发访问冲突的情况下执行此操作?
- 如何合并两个双重链接列表(访问下一个链接)
- 读取访问违规当前为0xCDCDCDCD,链接列表窗口
- 链接列表节点的访问违规:C
- 静态成员函数访问静态私有变量时的链接器错误
- 在删除双重链接列表中的最后一个元素时,请阅读访问违规行为
- 访问链接的列表项目从参考这些项目的参考文献中
- 如何在链接列表中访问下一个C
- 发生 JNI 调用 c++ dll "不满意链接错误: 对内存位置的无效访问"
- 访问注册表数据以设置链接器和包含路径
- 链接时突然无法访问私有方法
- 在单个链接列表中间删除一个节点,仅给定对该节点的访问
- 链接的不同类的列表,如何使用指针访问特定类功能
- Java/Python在C/C++中访问的动态链接库
- 未定义的引用;类公共函数在链接时不可访问
- 创建链接列表时发生访问冲突错误
- 动态链接 ~ 限制 DLL 的系统访问