
算法与数据结构
junlon2006
Coding for fun.
展开
-
几种常见的排序算法(C++版)
1、冒泡法 #include void bubble_sort(int a[], int n) { int loop_times = 0; int changes = 0; for(int i = 0; i < n - 1; i++) { for(int j = 0; j < n - i -1; j++) { if(a[j] > a[j+1]) { swa原创 2016-11-09 13:38:21 · 334 阅读 · 0 评论 -
少用,尽量不用递归
递归说到底,就是自己调用自己,是一种无穷迭代思维方式,简单粗暴的罗列。 递归对程序员的修养要求极高,无穷递归、栈溢出,各种问题,安全性比较难把握。 来段快排递归: template void quick_sort(T a[], int low, int hign) { int first = low; int last = hign; int key = a[first]; if(原创 2016-11-21 16:46:43 · 4912 阅读 · 1 评论 -
Merge Two Sorted Lists
https://leetcode.com/problems/merge-two-sorted-lists/ Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two list原创 2016-12-29 10:32:58 · 191 阅读 · 0 评论 -
将单向链表逆序
struct list { struct list *next; int value; }; //head--->p--->q---->r,将q的next指向p;p,q往前移动到q,r struct list* my_reverse(struct list *pList) { struct list *p,*q,*r; if(pList == NULL) return NULL; p原创 2017-01-16 09:59:53 · 266 阅读 · 0 评论 -
深入分析 Linux 内核链表
源地址:https://www.ibm.com/developerworks/cn/linux/kernel/l-chain/ 一、 链表数据结构简介 链表是一种常用的组织有序数据的数据结构,它通过指针将一系列数据节点连接成一条数据链,是线性表的一种重要实现方式。相对于数组,链表具有更好的动态性,建立链表时无需预先知道数据总量,可以随机分配空间,可以高效地在链表中的任意位置转载 2017-03-21 19:14:05 · 211 阅读 · 0 评论