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

苏州网站建设招标用jsp进行网站开发

苏州网站建设招标,用jsp进行网站开发,wordpress高端,抖音小程序官网1 问题 输入两个链表#xff0c;找出它们的第一个公共结点。 含有公共节点的两个链表的结构类似于下图中的链表#xff1a; 1 - 2 - 3 - 4 -5 2 - 4 -5 可以看到两个链表中有一个公共节点#xff0c;其中4节点就是这两个链表的公共节点 2 分析…1 问题 输入两个链表找出它们的第一个公共结点。 含有公共节点的两个链表的结构类似于下图中的链表 1 - 2 - 3 - 4 -5 2 - 4 -5 可以看到两个链表中有一个公共节点其中4节点就是这两个链表的公共节点   2 分析 既然题目是求公共节点说明一定存在这个节点然后我们可以发现两个链表的尾巴是一样都重合了是Y性结构我们先把长的链表的头移动到短的头那里然后一个接着下一个比较就行 3 代码实现 #include stdio.h #include stdlib.htypedef struct Node {int value;struct Node *next; } Node;/** 初始化结构体*/ struct Node* init(struct Node *node, int value) {node (struct Node*)malloc(sizeof(Node));if (node ! NULL){node-value value;//这个地方不要忘记设置为NULLnode-next NULL;return node;}return NULL; }/** 获取链表的长度*/ int length(Node *head) {if (head NULL)return 0;Node *p head;int length 0;while (p ! NULL){length;p p-next;}return length; }/*** 找到第一个公共的节点*/ struct Node* get_common(Node *head1, Node *head2) {if (head1 NULL || head2 NULL){return NULL;}int list1_length length(head1);int list2_length length(head2);Node *short_head NULL;Node *long_head NULL;int sub_len 0;if (list1_length list2_length){short_head head2;long_head head1;sub_len list1_length - list2_length;}else{short_head head1;long_head head2;sub_len list2_length - list1_length;}//移动长链表确保两个链表一样长while (sub_len 0){sub_len--;long_head long_head-next;}while (short_head ! NULL long_head ! NULL){if (short_head-value long_head-value){return short_head;}short_head short_head-next;long_head long_head-next;}return NULL; }int main() {Node *n1 NULL;Node *n2 NULL;Node *n3 NULL;Node *n4 NULL;Node *n5 NULL;Node *m1 NULL;Node *m2 NULL;Node *m3 NULL;n1 init(n1, 1);n2 init(n2, 2);n3 init(n3, 3);n4 init(n4, 4);n5 init(n5, 5);m1 init(m1, 2);m2 init(m2, 4);m3 init(m3, 5);if (n1 n2 n3 n4 n5){n1-next n2;n2-next n3;n3-next n4;n4-next n5;}if (m1 m2 m3){m1-next m2;m2-next m3;}Node *node get_common(n1, m2);if (node){printf(common node value is: %d\n, node-value);}else{printf(two list do not common value\n);}if (n1) {free(n1); n1 NULL;}if (n2) {free(n2); n2 NULL;}if (n3) {free(n3); n3 NULL;}if (n4) {free(n4); n4 NULL;}if (n5) {free(n5); n5 NULL;}if (m1) {free(m1); m1 NULL;}if (m2) {free(m2); m1 NULL;}if (m3) {free(m3); m1 NULL;}return 1; } 4 运行结果 common node value is: 4 5 总结 如果我们求链表的长度一般是这样的函数 /** 获取链表的长度*/ int length(Node *head) {if (head NULL)return 0;Node *p head;int length 0;while (p ! NULL){length;p p-next;}return length; } 一定要记到骨髓里面去。
http://www.pierceye.com/news/184285/

相关文章:

  • 网站怎样和首页做链接地址七星彩的网站怎么做的
  • 深圳h5模板建站wordpress 整合ucenter
  • 企业网站策划书下载google adsense
  • 安徽网站建设公司排名竞价托管就选微竞价
  • 笑话小网站模板html做移动网站快速排
  • c2c电子商务网站有哪些电商设计师和美工有什么区别
  • 长春电商网站建设价格低公司网站过期未续费会怎样
  • 农业综合管理网站建设做网站前期工作
  • 域名更换网站网站维护工作内容
  • 网站水印设置作教程长沙求职网招聘网
  • 八年级微机网站怎么做wordpress 链接转换
  • ppt做的模板下载网站有哪些内容wordpress 4.5.3中
  • 网站开发需求文档prd模板iis wordpress 404
  • 灰色链网站建设偃师建网站那家公司好
  • 文化网站前置审批网站运营系统
  • 现在做网站用什么学校网站的建设需求
  • 网页制作与网站建设技术大全 pdfhtml5移动端网站开发教程
  • 做任务可以给钱的网站php响应式网站模板下载
  • 平面素材设计网站东莞房价2023年最新房价走势
  • 做一个网站建设需要多少钱天津企业网站排名优化
  • 有关网站开发的论文网站建设哪公司
  • wordpress网站500导航 网站 分析
  • 软件网站开发市场前景试论述网上商城的推广技巧
  • 海洋生态文明建设的网站名廊坊网站建设电话
  • 做外贸在哪个网站比较好视频网站搭建源码
  • 网站代码优化视频教程动画制作专业大学排名
  • 安阳网站推广优化网站导航条背景图片
  • 静态网站需要数据库吗广州近期流行的传染病
  • 如何做国外的网站页面设计感想
  • 征婚网站认识的男人做定投保wordpress 中文 cms