节点,&节点和节点之间的差异 - >链接列表中的下一个

时间:2014-09-17 20:53:04

标签: c++ pointers linked-list

// 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?


}

2 个答案:

答案 0 :(得分:1)

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

请注意,最后,newNode将成为列表的头部,newNode-&gt; next将指向旧头部。

答案 1 :(得分:0)

&amp; newNode:节点内存中的地址 newNode:要操作的节点 newNode-&gt; next:下一个节点*指针。

相关问题