当只能访问一个节点时,如何删除这个节点 Posted on 2020-04-20 Words count in article: 137 | Reading time ≈ 1 当只能访问该节点时,如何删除该节点那就是鸠占鹊巢,将下一个结点的值和指向赋给当前节点,再删除下一个节点123456789101112131415161718192021/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: void deleteNode(ListNode* node) { //令当前节点的下一节点 ListNode *temp = node->next; //把下一个节点的所有信息赋给当前节点 node->val = temp ->val; node->next = temp->next; //删除下一个节点 delete temp; temp=NULL; }}; -------------本文结束,感谢您的阅读------------- Post author: Jason Post link: https://jasonxqh.github.io/2020/04/20/%E5%BD%93%E5%8F%AA%E8%83%BD%E8%AE%BF%E9%97%AE%E4%B8%80%E4%B8%AA%E8%8A%82%E7%82%B9%E6%97%B6%EF%BC%8C%E5%A6%82%E4%BD%95%E5%88%A0%E9%99%A4%E8%BF%99%E4%B8%AA%E8%8A%82%E7%82%B9/ Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 3.0 unless stating additionally.