- 博客(45)
- 资源 (2)
- 收藏
- 关注
原创 逆转字符串 C语言
#include #include char* Reverse(char *str){ if(str == NULL) return str; char *pLast = str + (strlen(str) - 1); char *pBegin = str; while(pBegin != pLast) {
2014-08-09 17:39:52
2666
原创 用条件变量实现阻塞队列
#include #include #include const int NUM = 20; struct node{ int val; struct node *next;};void node_ini(struct node *n, int i){ n->val = i; n->next = NULL;}
2014-07-18 17:19:41
942
原创 fedora 20下安装vim的C++补全插件clang_complete
fedora 20下安装vim的C++补全插件clang_complete
2014-07-13 16:38:53
2385
原创 快速排序代码
#include #include #include void swap(int *a, int *b){ int t = *a; *a = *b; *b = t;}int partition(int a[], int nLeft, int nRight){ int v = a[nRight]; int i = nLeft - 1;
2014-06-06 14:53:26
710
原创 Linux设备驱动程序代码 第2章 建立和运行模块
第2章 建立和运行模块1.资源下载电子书地址:pdf版:http://www.kuaipan.cn/file/id_12008874588517353.htmchm版:http://www.kuaipan.cn/file/id_12008874588517352.htm源码:http://www.kuaipan.cn/file/id_12
2012-12-16 15:12:05
1264
2
原创 Unix网络编程代码 第28章 原始套接字
第28章 原始套接字28.5 ping程序#define _GNU_SOURCE#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #incl
2012-01-18 20:16:18
2516
原创 Unix网络编程代码 第30章 客户/服务器程序设计范式
第30章 客户/服务器程序设计范式30.3 TCP测试用客户程序运行:./client 127.0.0.1 8888 1 5000 4000#define _GNU_SOURCE#include #include #include #include #include #include #include #include #include #include #inc
2012-01-17 01:04:02
1683
原创 Unix网络编程代码 第20章 广播
第20章 广播20.4 使用广播的dg_cli函数//运行前启动daytime服务,运行:./client 192.168.1.255,启动后,随便输入字符#include /* sockaddr_in{} and other Internet defns */#include #include #include #include #include #include #i
2012-01-13 23:58:28
696
原创 Unix网络编程代码 第17章 ioctl操作
第17章 ioctl操作17.6 get_ifi_info函数#define _GNU_SOURCE#include /* sockaddr_in{} and other Internet defns */#include /* ANSI C header file */#include #include #include #include #include #incl
2012-01-13 18:00:51
1348
原创 Unix网络编程代码 第16章 非阻塞式I/O
第16章 非阻塞式I/O16.2 非阻塞读和写:str_cli函数(修订版)//使用select#include /* sockaddr_in{} and other Internet defns */#include #include /* ANSI C header file */#include /* for syslog() */#include #include
2012-01-13 16:34:41
1056
原创 Unix网络编程代码 第14章 高级I/O函数
第14章 高级I/O函数14.2 套接字超时14.2.1 使用SIGALRM 为连接设置超时 #include /* sockaddr_in{} and other Internet defns */#include #include /* ANSI C header file */#include /* for syslog() */#include #include
2012-01-12 23:16:59
768
原创 Unix网络编程代码 第13章 守护进程和inetd超级服务器
第13章 守护进程和inetd超级服务器13.4 daemon_init函数13.4.1 作为守护进程运行的协议无关时间获取服务器程序运行: ./server localhost daytime查看日志: tail /var/log/syslog#define _POSIX_SOURCE#include #include #include /* basic socket
2012-01-12 20:38:08
1167
原创 Unix网络编程代码 第11章 名字与地址转换
第11章 名字与地址转换11.3 gethostbyname函数#define _BSD_SOURCE#include #include #include #include #include #include #include #define MAXLINE 4096 /* max text line length */void err_doit(int errnofl
2012-01-12 15:17:21
709
原创 Unix网络编程代码 第8章 基本UDP套接字编程
第8章 基本UDP套接字编程8.3 UDP回射服务器程序#include /* sockaddr_in{} and other Internet defns */#include #include #include #include #include #include /* ANSI C header file */#define MAXLINE 4096 /* max
2012-01-12 01:55:04
1025
原创 Unix网络编程代码 第7章 套接字选项
第7章 套接字选项7.3 检查选项是否受支持并获取默认值#define __need_timeval#include #include #include /* for TCP_xxx defines */#include #include /* sockaddr_in{} and other Internet defns */#include #include #in
2012-01-11 23:11:13
1064
原创 Unix网络编程代码 第6章 I/O复用:select、poll和epoll函数
第6章 I/O复用:select、poll和epoll函数6.4 str_cli函数(修订版)//使用select#define _POSIX_SOURCE#include /* sockaddr_in{} and other Internet defns */#include #include #include /* ANSI C header file */#inclu
2012-01-11 19:39:08
1192
原创 Unix网络编程代码 第5章 TCP客户/服务器程序示例
第3章 套接字编程简介3.4 字节排序函数#include #include #define CPU_VENDOR_OS "i686-pc-linux-gnu"int main(int argc, char **argv){ union { short s; char c[sizeof(short)]; } un; un.s = 0x0102; pri
2012-01-10 01:18:16
1458
原创 Unix网络编程代码 第1章 简介
1.2 一个简单的时间获取客户程序#include /* sockaddr_in{} and other Internet defns */#include #include /* ANSI C header file */#include /* for syslog() */#include #include #include #include #include
2012-01-08 21:35:59
790
原创 算法导论代码 第25章 每对顶点间的最短路径
第25章 每对顶点间的最短路径25.1 最短路径与矩阵乘法#include #include #include #include typedef struct graph_type *graph;struct edge { int u; int v; int w;};struct vertex { char str_vertex[256]; //顶点的字符串表示,
2011-12-31 11:37:50
1220
原创 算法导论代码 第24章 单源最源路径
第24章 单源最源路径24.1 Bellman-Ford算法#include #include #include #include #include typedef struct graph_type *graph;struct edge { int u; int v; int w;};struct graph_node { int key; int w; st
2011-12-30 19:03:49
1030
原创 算法导论代码 第23章 最小生成树
第23章 最小生成树22.2 Kruskal算法和Prim算法22.2.1 Kruskal算法#include #include #include #include typedef struct graph_type *graph;struct edge { int u; int v; int w;};struct graph_node { int key; i
2011-12-30 18:54:03
1115
原创 算法导论代码 第22章 图的基本算法
第22章 图的基本算法22.1 图的表示22.1.1 邻接表表示法#include #include #include typedef struct graph_type *graph;struct edge { int u; int v;};struct graph_node { int key; struct graph_node *next;};void
2011-12-30 18:45:27
1092
原创 算法导论代码 第21章 用于不相交集合的数据结构
第21章 用于不相交集合的数据结构21.2 不相交集体的链表表示#include #include #include typedef struct set_type *set;struct set_node { void *key; struct set_node *next; struct set_node *representative; //指向代表的集合元素};
2011-12-30 18:10:05
1054
原创 算法导论代码 第20章 斐波那契堆
第20章 斐波那契堆#include #include #include #include #include #include typedef struct fib_heap *heap;struct heap_node { void *key; int degree; bool mark; struct heap_node *child; struct heap_no
2011-12-30 18:07:28
1076
原创 算法导论代码 第19章 二项堆
第19章 二项堆#include #include #include #include #include typedef struct binomial_heap *heap;struct heap_node { void *key; int degree; struct heap_node *child; struct heap_node *sibling; struc
2011-12-30 18:06:15
873
原创 算法导论代码 第18章 B树
第18章 B树#include #include #include #include #include /*两个约定:(1)B树的根结点始终在主存中,因而无需对根做DISK_READ, 但是根结点被改变后,都需要对根结点做一次DISK_WRITE(2)任何被当作参数的结点被传递之前,要先对它们做一次DISK_READ*/#define DISK_READ(x)#define
2011-12-30 18:04:20
1241
原创 算法导论代码 第16章 贪心算法
第16章 贪心算法16.1 活动选择问题#include void recursive_activity_select(int s[], int f[], int i, int j, int select_set[], int *select_num){ int m = i + 1; while (m < j && s[m] < f[i]) { ++m; }
2011-12-30 16:57:05
852
原创 算法导论代码 第15章 动态规划
第15章 动态规划15.1 装配线调度#include #include enum { NUM = 6 };void fastest_way(int n,int a[][n], int t[][n - 1], int e[], int x[], int f[][n], int l[][n], int *fastest_time, int *last_line){ f[
2011-12-30 16:53:35
1008
原创 算法导论代码 第14章 数据结构的扩张
第14章 数据结构的扩张14.1 动态顺序统计#include #include #include typedef struct red_black_tree_type *tree;enum color_enum { color_red, color_black};struct tree_node { void *key; enum color_enum color;
2011-12-30 16:02:15
678
原创 算法导论代码 第13章 红黑树
#include #include #include typedef struct red_black_tree_type *tree;enum color_enum { color_red, color_black};struct tree_node { void *key; enum color_enum color; struct tree_node *parent;
2011-12-30 15:59:26
1341
原创 算法导论代码 第12章 二叉查找树
第12章 二叉查找树#include #include #include typedef struct binary_search_tree_type *tree;struct tree_node { void *key; struct tree_node *parent; struct tree_node *left; struct tree_node *right;
2011-12-30 15:57:23
512
原创 算法导论代码 第11章 散列表
第11章 散列表11.2 散列表#include #include /*通过链接法解决碰撞*/typedef struct hash_chain_type *hash;typedef struct list_type *list;struct list_node { void *key; struct list_node *prev; struct list_node *n
2011-12-30 15:55:12
654
原创 算法导论代码 第10章 基本数据结构
第10章 基本数据结构10.1 栈和队列10.1.1 栈10.1.1.1 基于数组实现#include #include #include typedef struct stack_type *stack;struct stack_type { int top; int num; void **array;};stack stack_create(int num)
2011-12-30 15:53:03
600
原创 算法导论代码 第9章 中位数和顺序统计学
第9章 中位数和顺序统计学9.1 最小值和最大值#include #include #include #include int minimum(int A[], int n){ int min = A[0]; for (int i = 1; i < n; i++) { if (min > A[i]) { min = A[i]; } } return mi
2011-12-30 15:48:39
637
原创 算法导论代码 第8章 线性时间排序
第8章 线性时间排序8.2 计数排序#include #include #include #include void counting_sort(int A[], int n, int k){ int *C = malloc(sizeof(int) * (k + 1)); for (int i = 0; i <= k; i++) { C[i] = 0; } for
2011-12-30 15:30:06
609
原创 算法导论代码 第7章 快速排序
第7章 快速排序7.1 快速排序的描述#include #include #include #include void swap(void *a, void *b, size_t elem_size){ if(a==NULL||b==NULL||a==b) return; char temp[elem_size]; /*变长数组 */ memcpy(temp, a, e
2011-12-30 15:20:01
579
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人