求大神, c++的问题

来源:3-5 链表编码实战(三)

qq_愿时光安好_04050009

2017-03-28 13:50

bool List::ListInsertHead(Node *pNode)

{

Node *temp = m_pList;

Node *newNode = new Node;

if (new Node == NULL)

return false;

newNode->data = pNode->data;

m_pList->next = newNode;

newNode->next = temp;

}

不明白为什么要加newNode 直接接上不就行了

写回答 关注

1回答

  • 如烟风云
    2017-04-06 22:56:26

    m_pList->next = newNode;

    newNode->next = temp;

    这两句有问题的,应该修改为

    newNode->next = m_pList->next;

    m_pList->next = newNode;

    陆_ 回复陆_

    错了,这个在构造函数中已经申请了一个头结点,还是楼主的对

    2019-03-15 22:28:07

    共 4 条回复 >

数据结构探险之线性表篇

线性表的主体顺序表和链表,让学员能够将知识融会贯通学以致用

57563 学习 · 257 问题

查看课程

相似问题