将下一个节点移回功能
Move Next Node Back Function
所以我正在尝试为DLL类编写一个名为MoveNextToBack
的函数。该函数的目的是将节点的下一个节点移动到列表的后面。这是我到目前为止所拥有的,但我认为它不完整:
void DLL::MoveNextToBack(Node *N){
// If N's next node is the end already, return
if(N->Next == Tail)
return;
// Change N's Next pointer to the one after N's current Next
N->Next = N->Next->Next;
// Change N's Next Next's Previous pointer to point to N
N->Next->Next->Prev = N;
// Move N to the end
N->Next->Next = Tail;
N->Next->Prev = Tail->Prev;
}
我错过了什么?
这应该有效
void DLL::MoveNextToBack(Node *N){
// If N's next node is the end already, return
if(N == NULL || N->Next == NULL || N->Next == Tail)
return;
//Pointer to the next node
Node *tmp = N->Next
//Point to the next, next node
Node *pmt = N->Next->Next;
// Change N's Next pointer to the one after N's current Next
N->Next = pmt;
// Change N's Next Next's Previous pointer to point to N
if (pmt != NULL)
pmt->Prev = N;
// Move tmp to the end
tmp->Prev = Tail;
tmp->Next = Tail->Next;
Tail->Next = tmp;
Tail = tmp;
}
相关文章:
- 在执行其他功能的同时播放动画(LED矩阵和Arduino/ESP8266)
- 反向给定链表中的K节点
- 多态性和功能结合
- 如果我只是不访问queue_front节点的子节点,而是将它们推到队列中呢?还是BFS吗
- 带内存和隔离功能的SQLite
- Boost Graph Library,修复节点大小
- 在CMakeLists.txt的安装功能中使用.cmake文件有什么用
- 类模板的成员功能的定义在单独的TU中完全专业化
- C++A*算法并不总是在路径中具有目标节点
- 有没有一种方法可以创建一个带有哈希表的数据库,该哈希表具有恒定时间查找功能
- 为什么我的打印功能之一删除节点
- 插入功能保持重新创建根节点
- 推送功能(将新节点添加到列表顶部)C
- 如何在C++中实现按级别计数/显示节点的功能
- 从GCC功能树节点中检索函数参数
- 将节点的数组传递到功能并返回一个节点数组
- 插入节点功能令人困惑
- 将下一个节点移回功能
- 节点删除功能的链表问题
- 为什么我的删除节点功能不起作用?