python可以做网站前端,重庆信息网官网,短视频推广计划,word免费素材大全大家好#xff0c;我是苏貝#xff0c;本篇博客带大家刷题#xff0c;如果你觉得我写的还不错的话#xff0c;可以给我一个赞#x1f44d;吗#xff0c;感谢❤️ 点击查看题目 思路: struct Node* copyRandomList(struct Node* head) {struct Node* curhead;//1.copy原链… 大家好我是苏貝本篇博客带大家刷题如果你觉得我写的还不错的话可以给我一个赞吗感谢❤️ 点击查看题目 思路: struct Node* copyRandomList(struct Node* head) {struct Node* curhead;//1.copy原链表并将其插入到原链表中while(cur){struct Node* copy(struct Node*)malloc(sizeof(struct Node));struct Node* nextcur-next;copy-valcur-val;cur-nextcopy;copy-nextnext;curnext;}//2.将copy-random指向cur-random的下一个节点curhead;while(cur){struct Node* copycur-next;if(cur-randomNULL){copy-randomNULL;}else{copy-randomcur-random-next;}curcur-next-next;}//3.将copy的链表取下来curhead;struct Node* newheadNULL;struct Node* tailNULL;while(cur){struct Node* copycur-next;struct Node* nextcopy-next;if(tailNULL){newheadtailcopy;}else{tail-nextcopy;tailtail-next;}cur-nextnext;curnext;}if(tail)tail-nextNULL;return newhead;
}好了那么本篇博客就到此结束了如果你觉得本篇博客对你有些帮助可以给个大大的赞吗感谢看到这里我们下篇博客见❤️