删除节点无效
Delete node wont work
我试图删除链表上的节点,但在删除命令之后,我试图在节点内显示数据,我仍然可以显示据称已删除的数据。搜索是我试图删除的节点
int position=0;
while(admintemp !=NULL)
{
position=position+1;
if(admintemp==search)
{
cout<<"found"<<position;
getch();
break;
}
admintemp = admintemp->next;
}
node *body = new node;
node *admintemp = new node;
if(position>0)
{
admintemp = adminhead;
for (int i= 1;i<position;i++)
{
body = admintemp;
admintemp = admintemp->next;
}
body->next=admintemp->next;
cout<<"deleting";
getch();
delete admintemp;
}
通过delete
d指针读取数据是"未定义行为" -这意味着编译器可以做任何它喜欢的事情,你的程序没有意义。
你可能得到你期望的结果,你可能得到崩溃,你可能得到从你鼻子里飞出来的恶魔。没有办法知道。程序完全无效,任何行为都是可以的。根据c++标准的规则,程序员有责任不调用未定义的行为-它可能编译并运行,但是你已经违反了规则,所以编译器没有义务做任何相同的事情(甚至任何事情)。
相关文章:
- 反向给定链表中的K节点
- 如果我只是不访问queue_front节点的子节点,而是将它们推到队列中呢?还是BFS吗
- Openssl 1.1.1d无效使用不完整的类型"struct dsa_st"
- 无法访问嵌套类.类的使用无效
- Boost Graph Library,修复节点大小
- C++A*算法并不总是在路径中具有目标节点
- 如何找到2个单链表的公共节点
- 计算每个节点的树高,帮助我解释这个代码解决方案
- 如果用户输入无效,如何使用字符串变量-C++重复输入命令
- 为什么我的删除节点函数实际上没有删除节点?
- 我们可以删除链表中静态内存中的节点吗
- 如何解决错误:SCIP C++中的 SCIP 阶段无效 <10>
- 解析序列/映射节点时出现无效的 yaml 节点错误
- 在没有参数列表的情况下无效使用模板名称"节点"
- 添加新节点后,链接列表的负责人总是无效
- 包含具有无效位置的节点引用的方式
- 二进制树中的节点为无效
- XML从UnicodeString创建CData节点时出现无效字符
- 删除节点无效
- 获取类型的错误 无效使用不完整类型的"结构节点"