链表题目整理
来源:互联网 发布:好伙伴物流软件 编辑:程序博客网 时间:2024/06/06 20:37
链表逆序:
void Reverse(Node *head){if (head == NULL)return;Node *pre, *cur, *nex;pre = head;cur = head->next;while (cur){nex = cur->next;cur->next = pre;pre = cur;cur = nex;}head->next = NULL;head = pre;}
链表归并:
Node *Merge(Node *head1, Node *head2){if (head1 == NULL)return head2;if (head2 == NULL)return head1;Node *head, *p1, *p2;if (head1->data < p2->data){head = head1;p1 = head1->next;p2 = head2;}else{head = head2;p1 = head1;p2 = head2->next;}Node *cur = head;while (p1 != NULL && p2 != NULL){if (p1->data <= p2->data){cur->next = p1;cur = p1;p1 = p1->next;}else{cur->next = p2;cur = p2;p2 = p2->next;}}if (p1 == NULL)cur->next = p2;if (p2 == NULL)cur->next = p1;return head;}
阅读全文
0 0
- 链表题目整理
- 链表题目整理(持续更新)
- 链表题目整理(C语言实现)
- 链表的各种题目整理
- 链表的各种题目整理(C语言实现)
- 链表的各种题目整理(C语言实现)
- 【题目整理】
- 写的很好 链表的各种题目整理(C语言实现)
- JAVA面试题目整理
- JAVA笔试题目整理
- POJ 题目整理
- 某博友整理算法题目
- 某博友整理算法题目
- 面试题目整理
- POJ题目整理
- 面试关键题目整理
- IOS面试题目 整理
- 嵌入式C题目整理
- Valid Sudoku--LeetCode
- Laravel 用js jquery,调Post请求时,出现了500错误
- 欢迎使用CSDN-markdown编辑器
- 【笔记+模板】 manacher算法
- test
- 链表题目整理
- GameEntity(一) —— CampType
- SSH整合 xml版 和注解版
- [USACO17OPEN]Where's Bessie? 贝西在哪呢
- CatBoost: A machine learning library to handle categorical (CAT) data automatically MACHINE LEARNING
- 这是别人的添加监听事件的方法
- bootstrap之transition
- Badboy自动化测试工具6 Variable Setter
- React中constructor(){}