用于删除链接列表的节点的伪代码
Pseudocode for removing a node of a linked list
假设p是指向链表中某个节点的指针,*p不是尾节点。删除*p之后的节点的步骤是什么?每一步使用一个英语短句。
我的想法是:1) 创建一个class node类型的临时变量,并在临时变量旁边分配p->——将此变量称为temp。
2) 将temp的下一个指针分配给p的下一指针。
3) 将*p之后节点的下一个指针设置为NULL。
这使得*p之后的节点不存在于链表中,但它仍然占用内存吗?或者,由于在步骤3中我将指针设置为NULL,所以我删除的节点现在没有更多内存了?我需要使用free()还是delete函数?
您似乎在试图描述删除单个链表中的节点。
在您的描述中,正确的是您需要一个指向已删除节点的临时变量。
因此,步骤可以如下。
1) define a temporary pointer to Node and assign the value in p->next to the temporary pointer.
2) assign the value in data member next of the temporary pointer to the data member next of p.
3) delete node pointed to by the temporary pointer.
在C++中,代码将按照以下方式
1) Node *temp = p->next;
2) p->next = temp->next;
3) delete temp;
相关文章:
- 如何实现此伪代码?
- 将节点 js 代码集成到 cpp 库时出错
- 有人可以为此提供伪代码吗?
- 如何计算以下伪代码的封闭形式
- 为赋值编写伪代码,并希望仔细检查它是否有意义
- 为什么这个从链表中删除节点的代码不起作用?
- 将伪代码转换为C++
- 我误解了这个伪代码了吗
- 在C 中编写一个简单的排序算法以及伪代码版本
- 用于删除链接列表的节点的伪代码
- 在cpp中创建嵌套对象.下面的伪代码中的函数调用序列是什么
- 我试图通过 c++ 中的相关实验室作业理解的类中给出的伪代码
- 将伪代码转换为C++
- 使合并排序几乎与家庭作业的伪代码相同
- 尝试将伪代码转换为合并排序的实际代码
- 日期函数定义的伪代码
- CPP项目的伪代码
- BFS的伪代码(来自算法设计,第二版)混淆
- 接收访问无线介质到有限状态机的伪代码
- 寻找8x8(或nxn)离散余弦变换(DCT)/IDCT伪代码