当前位置: 首页 > news >正文

网站可以做充值吗扁平网站 文案

网站可以做充值吗,扁平网站 文案,两学一做网站 苏州,网站制作过程方法一:暴力求解 1️⃣遍历原链表,复制节点尾插 2️⃣更新random,原链表中的random对应第几个节点则复制链表中的random就对应第几个 📖Note 不能通过节点中的val判断random的指向,因为链表中可能存在两个val相等的节点…

方法一:暴力求解

1️⃣遍历原链表,复制节点尾插

2️⃣更新random,原链表中的random对应第几个节点则复制链表中的random就对应第几个

📖Note

不能通过节点中的val判断random的指向,因为链表中可能存在两个val相等的节点

//创建节点
struct Node* BuyNode(int x)
{struct Node* newnode = (struct Node*)malloc(sizeof(struct Node));newnode->val = x;newnode->next = NULL;return newnode;
}//找到random对应的节点是第几个
int FindRandom(struct Node* head, struct Node* random)
{int count = 1;while (head){if (head == random){return count;}else {count++;head = head->next;}}return count;
}struct Node* copyRandomList(struct Node* head) {struct Node* guard = (struct Node*)malloc(sizeof(struct Node));guard->next = NULL;struct Node* tail = guard;struct Node* cur = head;//复制原链表while (cur){struct Node* newnode = BuyNode(cur->val);tail->next = newnode;tail = tail->next;cur = cur->next;}//tail和cur都指向新链表的头tail = guard->next;struct Node* tmp = head;//更新randomwhile (tail){//在原链表这种判断random指向的节点是第几个int count = FindRandom(head, tmp->random);tmp = tmp->next;//更新复制链表中的randomcur = guard->next;while (count--){tail->random = cur;if (cur){cur = cur->next;}}tail = tail->next;}struct Node* newhead = guard->next;free(guard);return newhead;}

方法二:

1️⃣拷贝原节点,并链接在原节点之后

2️⃣更新拷贝节点中的random

拷贝节点中的random指向的是原节点中random指向节点的下一个节点

3️⃣将拷贝的节点解下来构成新的复制链表

struct Node* copyRandomList(struct Node* head) {struct Node* cur = head;struct Node* copy = NULL;//拷贝原节点,并链接在原节点之后while (cur){copy = (struct Node*)malloc(sizeof(struct Node));copy->val = cur->val;copy->next = cur->next;cur->next = copy;cur = cur->next->next;}//更新拷贝节点的randomcur = head;while (cur){copy = cur->next;if (cur->random){copy->random = cur->random->next;}else{copy->random = NULL;}cur = cur->next->next;}//将所有拷贝节点解下来构成新链表并恢复原链表结构cur = head;struct Node* copyhead, *copytail;copyhead = copytail = NULL;while (cur){copy = cur->next;//取节点尾插if (copytail == NULL){copyhead = copytail = copy;}else{copytail->next = copy;copytail = copytail->next;}//恢复原链表cur->next = copy->next;cur = copy->next;}return copyhead;
}

http://www.yayakq.cn/news/398021/

相关文章:

  • 洛阳新光建站软件公司都是干什么的
  • 福田营销型网站建站推广外包网站空间1g多少钱
  • 网站建设订制版合同模板做网站买空间
  • 做视频网站怎么盈利模式中国建设银行官方网站登录入口
  • 大连住房和建设局网站国外旅游网站模板下载
  • 零基础网站建设教学在哪里网站结构图怎么画
  • 自己网站建设容易吗最牛的SEO教程网站
  • 广州比较好的网站建设做地方网站要办什么证
  • 厦门市网站建设公司电子版邀请函制作软件免费
  • 商务网站开发与建设论文广告门
  • 网站关键词快照优化做网站专题的软件
  • 网站建设工作室怎么接单吴中区网站建设
  • 网站建设交接表做外贸网站注意
  • 手机网站建设用乐云seo房地产开发商是干什么的
  • 如何找回网站备案密码汕头网站建设方案外包
  • 做网站怎么写代码asp做留言板网站
  • 百度收录的网站标题 --制定商务网站建设时
  • 大佬做的魔法少女网站网站建设 豫icp备
  • 上海空灵网站设计设计图纸用什么软件
  • 做电影网站怎么挣钱如何做热词网站
  • 现在很多网站都是wordpress网站国际推广
  • 试看30秒做受小视频网站学习网站开发技术
  • 建设工程施工合同范本哪个网站网站建设 gei l f
  • 网站建设中忽略的字体侵权行为wordpress文章上头条
  • jsp网站开发实例标题栏软文营销的经典案例
  • 北京网站建设哪家好上海猎头公司对个人怎么收费
  • 保定手机网站赣州市建设工程造价管理网站
  • 天津营销网站建设百度网站的安全建设方案
  • 做app和做网站相同和区别wordpress首页导航添加
  • 学做美食看哪个网站搜外滴滴友链