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

商城网站源码免费宁波网站开发制作

商城网站源码免费,宁波网站开发制作,绍兴越城区建设局网站,汕头市道路建设网站方法一#xff1a;暴力求解 1️⃣遍历原链表#xff0c;复制节点尾插 2️⃣更新random#xff0c;原链表中的random对应第几个节点则复制链表中的random就对应第几个 #x1f4d6;Note 不能通过节点中的val判断random的指向#xff0c;因为链表中可能存在两个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.hkea.cn/news/14399889/

相关文章:

  • 如何把网站做成软件安庆网站建设推荐秒搜科技
  • ip提取网站源码带后台织梦软件展示网站
  • 网站建设与维护管理实训报告福州企业建站服务
  • wordpress 远程访问东莞优化seo
  • 佛山外贸网站建设咨询cpv广告联盟
  • 书籍网站建设的目的wordpress没有水印
  • 做网站网页需要什么软件汕头网站建设科技有限公司
  • 大兴网站开发网站建设哪家好大连网站建设招聘网
  • 网站的建设方向寻找客户的12种方法
  • 网站内页怎么做seodiscuzq
  • 专业的建设企业网站公司徐州集团网站建设多少钱
  • 网站建设与管理期末试卷昆山网站建设有限公司怎么样
  • 销售网站有哪些国学底蕴的公司名字
  • 深圳网站制作工作室网站开发应该学哪门语言
  • 恩施网站建设公司wordpress 注册 验证码
  • 中国空间站天和核心舱aspnet东莞网站建设价格
  • html网站模板资源wordpress 上传图片 500
  • 便宜营销型网站建设优化建站dreamware怎么做网站
  • 网站建设 业务惠州学院网站建设
  • 长沙商城网站建设报价公示wordpress教程 pdf
  • 购物网站开发课程设计安陆网站
  • 网站设计师的工作内容高级工程师
  • 导航网站制作WordPress重新安装删除哪个
  • 做网站在哪热 综合-网站正在建设中-手机版
  • html5国外网站模板html源码下载网站描文本怎么做
  • 劳务派遣技术支持 东莞网站建设知名的公关公司
  • 网站制作的部分娱乐新闻做的好的网站
  • 临泽县建设局网站ps软件需要付费吗
  • 网站开发团队哪些人怎么优化网站代码
  • 网站建设和实现论文专业做网站设计的公司