HEIMIIY 2018-06-01 13:16 采纳率: 0%
浏览 671

单链表的删除。为什么它删除运行显示的是删除的地址

图片说明
#include"List.h"
#include
using namespace std;
List::List(){
m_pList=new Node;
m_pList->data=0;
m_pList->next=NULL;
m_iLength=0;

};
List::~List(){
ClearList();
delete m_pList;
m_pList=NULL;

}
void List::ClearList(){
Node *currentNode=m_pList->next;
while(currentNode!=NULL)
{
Node *temp=currentNode->next;
delete currentNode;
currentNode=temp;
}
m_pList->next=NULL;

}
bool List::ListInsert(int i,Node *pNode)
{
if(im_iLength){
return false;
}

    Node *currentNode=m_pList;
    for(int k=0;k<i;k++)
    {
        currentNode=currentNode->next;
    }
    Node *newNode=new Node;
    newNode->data=pNode->data;
    newNode->next=currentNode->next;
    currentNode->next=newNode;
    m_iLength++;
    return true;

}

bool List::ListDelete(int i,Node *pNode)
{
if(i=m_iLength){
return false;

}
Node *currentNode=m_pList;
Node *currentNodeBefore=NULL;
for(int k=0;k<=i;k++){
    currentNodeBefore=currentNode;
    currentNode=currentNode->next;
    currentNodeBefore->next=currentNode->next;
    pNode->data=currentNode->data;
    delete currentNode;
    currentNode=NULL;
}
m_iLength--;
return true;

}
bool List::ListInsertHead(Node *pNode){
Node *temp=m_pList->next;
Node *newNode=new Node;
newNode->data=pNode->data;
m_pList->next=newNode;
newNode->next=temp;
return true;

}

void List::Tranverse()
{
Node*currentNode=m_pList;
while(currentNode->next!=NULL)
{
currentNode=currentNode->next;
cout<data<<endl;
}
}

int main()
{
List *pList=new List();
Node nodel;
nodel.data=3;

pList->ListInsert(0,&nodel);
Node node5;
node5.data=7;
pList->ListInsert(1,&node5);


cout<<"未删除节点前"<<endl;
pList->Tranverse();

Node temp;
pList->ListDelete(0,&temp);
cout<<"删除节点后"<<endl;
pList->Tranverse();

cout<<"被删除的节点是"<<&temp<<endl;

system("pause");

}

  • 写回答

2条回答

  • yyyyyyyyyyhsj 2018-06-01 14:34
    关注

    取地址取得是指针地址

    评论

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办