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 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题