简体   繁体   English

如何理解链表中的双指针

[英]how to understand double pointers in a linked list

i found a useful page which explained how to use double pointers in a linked list . 我找到了一个有用的页面,该页面解释了如何在链接列表中使用双指针

But there are a few points that i could not understand. 但是有几点我无法理解。

void AddNodeSorted(node* pNewNode)
{
  node** ppScan = &pRootNode;
  while(*ppScan != NULL && compare(*ppScan,pNewNode))
    ppScan = &(*ppScan)->pNext;

  pNewNode->pNext = *ppScan;
  *ppScan = pNewNode;
}

In this function, I could not understand how the last two lines work. 在此功能中,我无法理解最后两行的工作方式。 In my point of view, after the while loop , the new item needs to insert before the element which ppScan indirectly points to. 在我看来,在while loop ,新项目需要在ppScan间接指向的元素之前插入。

So pNewNode->pNext = *ppScan works alright. 所以pNewNode->pNext = *ppScan可以正常工作。 Then what's the meaning of *ppScan = pNewNode ? 那么*ppScan = pNewNode什么意思? pNewNode->next = pNewNode ?? pNewNode->next = pNewNode ??

since "ppScan = &(*ppScan)->pNext;","*ppScan = pNewNode;" 因为“ ppScan =&(* ppScan)-> pNext;”,“ * ppScan = pNewNode;” will let the last element to point to the new node. 将让最后一个元素指向新节点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM