Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.
Quick StartCreate a new post1$ hexo new "My New Post"
More info: Writing
Run server1$ hexo server
More info: Server
Generate static files1$ hexo generate
More info: Generating
Deploy to remote sites1$ hexo deploy
More info: Deployment
ext2文件体系
对文件进行操作文件的磁盘存放stat(用法)1int stat(const char *path, struct stat *buf);
参数含义char *path 传入文件的路径
struct stat *buf 指向一个 struct stat 类型的指针,该结构用于存储文件的状态信息
调用成功后,buf 会填充相关数据。
1234567891011121314151617181920#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> #include <sys/stat.h> #include <sys/types.h> int main(int argc,char *argv[]){ struct stat s_buf; if(argc<2){ printf("./mycp src dest\n"); ...
快速排序步骤1 确定分界点
开始 | 中间值 | 随机值2 调整区间
第一区间小于(X)
第二区间大于等于(X) 3 递归处理左右两边
快速排序思路
代码模板
1234567891011void quick_sort(int q[], int l, int r) { if (l >= r) return; int x = q[(i+j+1)/2], i = l - 1, j = r + 1; while (i < j) { do i++; while (q[i] < x); do j--; while (q[j] > x); if (i < j) swap(q[i], q[j]); } quick_sort(q, l, i-1); quick_sort(q, j + 1, r); }
1if (l >= r) return;
首先进行边界判断,如果指针不同则直接退出
12345 ...
归并排序归并排序的介绍
是一种经典的基于分治策略的排序算法,其核心思想是将一个数组分成两个或多个子数组,对每个子数组进行排序,然后将排序好的子数组合并成一个最终的有序数组。
归并排序 ——-> 分治
步骤
确定分界点
mid = (i+r)/2
递归排序
归并 —- 合二为一
确定分界点
分界点可以取任意值|中间值
对分开的值进行两边的递归排序最后可以获得两组排好了的数据,将两组数据合二为一下面用图示来具体分析过程
主要步骤
分别确定两指针从两端的数据头开始
1int k = 0, i = l, j = mid + 1;
逐个取出数据后进行大小判断,再先后为temp赋值,temp为临时变量存储合二为一的数据
不断重复操作
1234567while (i <= mid && j <= r) { if (q[i] <= q[j]) { temp[k++] = q[i++]; } else { temp[k++] = ...
12345678int main() { struct strbuf sb; strbuf_init(&sb, 10); strbuf_attach(&sb, "xiyou", 5, 10); assert(strcmp(sb.buf, "xiyou") == 0); strbuf_addstr(&sb, "linux"); assert(strcmp(sb.buf, "xiyoulinux") == 0); strbuf_release(&sb);}
要想实现这个缓存区需要进行四个步骤依次处理
strbuf_init 的作用是开辟一个新的内存空间
strbuf_attach 将首次的字符串,放进新的缓冲区中
strbuf_addstr 继续追加新的字符串
strbuf_free 对其进行释放,释放整个内容空间
12345struct strbuf { int len; int aclloc; ...

