备案通过网站还是打不开怎么用网站做转换服务器
web/
2025/9/29 20:49:28/
文章来源:
备案通过网站还是打不开,怎么用网站做转换服务器,wordpress圈子,哈尔滨网站制作网页基本的算法实践在上一篇博文#xff0c;这篇博文向大家详细展示一下数据结构的高级应用#xff0c;可能有些难#xff0c;但这是重点#xff0c;实用性很强#xff0c;而且用的好往往事半功倍#xff0c;想获得力量吗#xff0c;开整#xff1a;
我把他们分为这几块这篇博文向大家详细展示一下数据结构的高级应用可能有些难但这是重点实用性很强而且用的好往往事半功倍想获得力量吗开整
我把他们分为这几块
链表反转反转单向链表或双向链表。检测链表环判断链表中是否存在环。合并两个有序链表将两个有序链表合并成一个有序链表。从链表中删除重复节点删除链表中的重复节点。链表排序对链表进行排序例如归并排序。
下面一一用代码给出展示代码完整可以直接复制下来自己摸索自己修改执行也可以自己保留复习话不多说代码见
C语言实现单向链表的高级操作
1. 链表反转
ListNode* reverse_list(ListNode* head) {ListNode* prev NULL;ListNode* current head;ListNode* next NULL;while (current ! NULL) {next current-next;current-next prev;prev current;current next;}return prev;
}2. 检测链表环
int has_cycle(ListNode* head) {ListNode *slow head, *fast head;while (fast ! NULL fast-next ! NULL) {slow slow-next;fast fast-next-next;if (slow fast) {return 1;}}return 0;
}3. 合并两个有序链表
ListNode* merge_sorted_lists(ListNode* l1, ListNode* l2) {if (!l1) return l2;if (!l2) return l1;if (l1-value l2-value) {l1-next merge_sorted_lists(l1-next, l2);return l1;} else {l2-next merge_sorted_lists(l1, l2-next);return l2;}
}4. 从链表中删除重复节点
void remove_duplicates(ListNode* head) {ListNode* current head;while (current ! NULL current-next ! NULL) {if (current-value current-next-value) {ListNode* next_next current-next-next;free(current-next);current-next next_next;} else {current current-next;}}
}5. 链表排序归并排序
ListNode* sorted_merge(ListNode* a, ListNode* b) {if (!a) return b;if (!b) return a;if (a-value b-value) {a-next sorted_merge(a-next, b);return a;} else {b-next sorted_merge(a, b-next);return b;}
}void front_back_split(ListNode* source, ListNode** front, ListNode** back) {ListNode* fast source-next;ListNode* slow source;while (fast ! NULL) {fast fast-next;if (fast ! NULL) {slow slow-next;fast fast-next;}}*front source;*back slow-next;slow-next NULL;
}void merge_sort(ListNode** head_ref) {ListNode* head *head_ref;if ((head NULL) || (head-next NULL)) {return;}ListNode* a;ListNode* b;front_back_split(head, a, b);merge_sort(a);merge_sort(b);*head_ref sorted_merge(a, b);
}C实现双向链表的高级操作
1. 链表反转
void reverse_list() {DoubleListNode *temp nullptr;DoubleListNode *current head;while (current ! nullptr) {temp current-prev;current-prev current-next;current-next temp;current current-prev;}if (temp ! nullptr) {head temp-prev;}
}2. 检测链表环
bool has_cycle() {DoubleListNode *slow head, *fast head;while (fast ! nullptr fast-next ! nullptr) {slow slow-next;fast fast-next-next;if (slow fast) {return true;}}return false;
}3. 合并两个有序链表
DoubleListNode* merge_sorted_lists(DoubleListNode* l1, DoubleListNode* l2) {if (!l1) return l2;if (!l2) return l1;if (l1-value l2-value) {l1-next merge_sorted_lists(l1-next, l2);if (l1-next ! nullptr) {l1-next-prev l1;}l1-prev nullptr;return l1;} else {l2-next merge_sorted_lists(l1, l2-next);if (l2-next ! nullptr) {l2-next-prev l2;}l2-prev nullptr;return l2;}
}4. 从链表中删除重复节点
void remove_duplicates() {DoubleListNode* current head;while (current ! nullptr) {DoubleListNode* runner current-next;while (runner ! nullptr) {if (current-value runner-value) {DoubleListNode* next runner-next;if (runner-prev) {runner-prev-next runner-next;}if (runner-next) {runner-next-prev runner-prev;}delete runner;runner next;} else {runner runner-next;}}current current-next;}
}5. 链表排序归并排序
DoubleListNode* sorted_merge(DoubleListNode* a, DoubleListNode* b) {if (!a) return b;if (!b) return a;if (a-value b-value) {a-next sorted_merge(a-next, b);a-next-prev a;a-prev nullptr;return a;} else {b-next sorted_merge(a, b-next);b-next-prev b;b-prev nullptr;return b;}
}void split(DoubleListNode* source, DoubleListNode** front, DoubleListNode** back) {DoubleListNode* fast source-next;DoubleListNode* slow source;while (fast ! nullptr) {fast fast-next;if (fast ! nullptr) {slow slow-next;fast fast-next;}}*front source;*back slow-next;slow-next nullptr;
}void merge_sort(DoubleListNode** head_ref) {DoubleListNode* head *head_ref;if ((head nullptr) || (head-next nullptr)) {return;}DoubleListNode* a;DoubleListNode* b;split(head, a, b);merge_sort(a);merge_sort(b);*head_ref sorted_merge(a, b);
}是不是发现了一个尽分享干货的博主创作属实不易希望大家珍惜
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/84088.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!