gpt4 book ai didi

c++ - node, & node 和 node->next in 链表的区别

转载 作者:行者123 更新时间:2023-11-28 06:41:20 28 4
gpt4 key购买 nike

// Program to insert node at front in linked list.

//这是一个简单的链表程序,但我不明白两者之间的区别 //&newNode、newNode 和 newNode 的值->next

void PushAtFrontLinkList(int value)
{
if(head==NULL)
{

head=tail;
}
node* newNode=new node();
newNode->data=value;
newNode->next=head;
head=newNode;


// Trying to differentiate between data contained in newNode and &newNode and newNode->next
cout<<"just new node"<<newNode<<endl; // what will be contained in newNode? cout<<"address of node"<<&newNode<<endl; // what will be contained in &newNode?
cout<<"new node next"<<newNode->next<<endl; // It will be the address of the next node?


}

最佳答案

newNode 将包含您刚刚创建的新节点对象的地址。对于 newNode->next,它包含列表中下一个节点的地址。

注意最后,newNode 将成为链表的头部,newNode->next 将指向旧的头部。

关于c++ - node, & node 和 node->next in 链表的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25900158/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com