
算法
文章平均质量分 76
MoXiaopeng
linux服务器开发程序员
展开
-
算法导论代码 第6章 堆排序
第6章 堆排序6.4 堆排序算法#include #include #include #include int parent(int i){ return (i - 1) / 2;}int left_child(int i){ return i * 2 + 1;}int right_child(int i){ return i * 2 + 2;}voi原创 2011-12-30 15:17:02 · 633 阅读 · 0 评论 -
算法导论代码 第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 · 682 阅读 · 0 评论 -
算法导论代码 第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 · 853 阅读 · 0 评论 -
算法导论代码 第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 · 1243 阅读 · 0 评论 -
算法导论代码 第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 · 1080 阅读 · 0 评论 -
算法导论代码 第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 · 1226 阅读 · 0 评论 -
快速排序代码
#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 · 714 阅读 · 0 评论 -
用条件变量实现阻塞队列
#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 · 946 阅读 · 0 评论 -
递归合并有序链表C语言
递归逆转链表和递归合并有序链表的代码原创 2014-07-11 14:58:52 · 2445 阅读 · 0 评论 -
位图算法 C语言
位图算法 C语言原创 2014-08-06 00:17:05 · 2962 阅读 · 0 评论 -
C语言反转单链表
反转单链表 定义一个函数,输入一个链表的头结点,反转该链表并输出反转后链表的头结点。原创 2014-07-22 17:10:57 · 22988 阅读 · 1 评论 -
逆转字符串 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 · 2670 阅读 · 0 评论 -
算法导论代码 第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 · 516 阅读 · 0 评论 -
算法导论代码 第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 · 642 阅读 · 0 评论 -
算法导论代码 第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 阅读 · 0 评论 -
算法导论代码 第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 · 583 阅读 · 0 评论 -
算法导论代码 第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 · 1093 阅读 · 0 评论 -
算法导论代码 第2章 算法入门
前言这文档是根据《算法导论》第2版的伪代码用C语言写的代码,因为用到了c99的一些特性,如变长数组。需要用gcc指定选项-std=c99编译,不支持VC。参考书:算法导论第2版电子版:http://www.kuaipan.cn/file/id_12008874588516081.htmlC语言程序设计_现代方法(第2版)电子版:http://www.kuaipan.cn/f原创 2011-12-30 15:06:50 · 890 阅读 · 0 评论 -
算法导论代码 第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 · 602 阅读 · 0 评论 -
算法导论代码 第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 阅读 · 0 评论 -
算法导论代码 第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 · 1342 阅读 · 0 评论 -
算法导论代码 第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 · 1016 阅读 · 0 评论 -
算法导论代码 第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 · 874 阅读 · 0 评论 -
算法导论代码 第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 · 1058 阅读 · 0 评论 -
算法导论代码 第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 · 1032 阅读 · 0 评论 -
算法导论代码 第5章 概率分析和随机算法
第5章 概率分析和随机算法5.1 雇用问题#include #include #include void hire_assistant(int A[], int n){ int best = 0; printf("hire:"); for (int i = 0; i < n; i++) { if (A[i] > best) { best = A[i];原创 2011-12-30 15:12:07 · 710 阅读 · 0 评论 -
翻转句子中单词的顺序 C语言
C语言 字符串 算法原创 2014-08-10 15:55:55 · 10386 阅读 · 0 评论