1 #include<iostream>
2
3 struct Node
4 {
5 int data;
6 Node *next;
7 };
8
9 typedef struct Node Node;
10
11 Node *Reverse(Node *head)
12 {
13 if (NULL == head || NULL == head->next)
14 return head;
15 Node *p1 = head;
16 Node *p2 = p1->next;
17 Node *p3 = p2->next;
18 p1->next = NULL;
19 while (p3 != NULL)
20 {
21 p2->next = p1;
22 p1 = p2;
23 p2 = p3;
24 p3 = p3->next;
25 }
26
27 p2->next = p1;
28 head = p2;
29 return head;
30 }
31
32 // 循环算法
33 Node *Merge(Node *head1, Node *head2)
34 {
35 if (NULL == head1)
36 return head2;
37 if (NULL == head2)
38 return head1;
39 Node *head = NULL;
40 Node *p1 = NULL;
41 Node *p2 = NULL;
42 if (head1->data < head2->data)
43 {
44 head = head1;
45 p1 = head1->next;
46 p2 = head2;
47 }
48 else
49 {
50 head = head2;
51 p2 = head2->next;
52 p2 = head1;
53 }
54
55 Node *cur = head;
56 while (NULL!=p1 && NULL!=p2)
57 {
58 if (p1->data < p2->data)
59 {
60 cur->next = p1;
61 cur = p1;
62 p1 = p1->next;
63 }
64 else
65 {
66 cur->next = p2;
67 cur = p2;
68 p2 = p2->next;
69 }
70 }
71 if (NULL == p1)
72 cur->next = p2;
73 if (NULL == p2)
74 cur->next = p1;
75
76 return head;
77 }
78
79 // 递归算法
80 Node *MergeRecursive(Node *head1, Node *head2)
81 {
82 if (NULL == head1)
83 return head2;
84 if (NULL == head2)
85 return head1;
86 Node *head = NULL;
87
88 if (head1->data < head2->data)
89 {
90 head = head1;
91 head->next = MergeRecursive(head1->next, head2);
92 }
93 else
94 {
95 head = head2;
96 head->next = MergeRecursive(head1, head2->next);
97 }
98
99 return head;
100 }
101
102 int main(void)
103 {
104 return 0;
105 }

最新文章

  1. Android 四大组件之一(Activity)
  2. 慕课网-安卓工程师初养成-2-7 Java中变量的使用规则
  3. ZLG_GUI配置与函数介绍
  4. AlloyTouch实现下拉刷新
  5. MFC文档、视图和框架
  6. 从你的u盘启动:30天自制操作系统第四天u盘启动学习笔记
  7. aliyun硬盘挂载
  8. CURL基础
  9. UVA 707 - Robbery(内存搜索)
  10. GoogleCodeJam
  11. 原生 JS Ajax,GET和POST 请求实例代码
  12. 一个想法(续四):IT技术联盟创业众筹进度公示
  13. 在 React 中使用 JSX 的好处
  14. Alibaba FastJson 常用方法使用指南
  15. SpringBoot使用WebFlux响应式编程操作数据库
  16. Oracle 在存储过程或函数中执行字符串sql
  17. C#并口热敏小票打印机打印位图包括芯片的写入
  18. python + opencv 环境配置
  19. Spark Standalone模式HA环境搭建
  20. windows 10 部署flask web

热门文章

  1. 关于Spring Boot的博客集合
  2. 深入Jar包:Gradle构建可执行jar包与访问jar包中文件夹与文件
  3. Java一些概念
  4. 2020 ICPC Universidad Nacional de Colombia Programming Contest
  5. zjnu1786 PROSJEK(二分)
  6. Codeforces Round #544 (Div. 3) E. K Balanced Teams (DP)
  7. HDU - 3281 dp
  8. 表达式目录树插件xLiAd.SqlEx.Core
  9. CF1462-E1. Close Tuples (easy version)
  10. 微服务架构学习Day01-SpringBoot入门