![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法导论
文章平均质量分 61
董道不渝
余将董道而不豫兮
展开
-
找第j小元素(递归实现)
//该程序只能实现互异元素的查找 #include #include #include #define swap(x, temp, y) (temp = x, x = y, y = temp) //找到[p,r]之间坐标z+1,左边全小于该坐标处值,右边大于等于该坐标处值 int random_partition(int a[], int p, int r) { int原创 2014-10-14 13:41:00 · 358 阅读 · 0 评论 -
找第j小元素(最坏情况为线性时间)
#include #include #define swap(x, temp, y) (temp = x, x = y, y = temp) //在[p,r]内找到中值mid_value,并用flag记录下标,使a[flag]与a[r]交换,利用快排思想使中值左边小于它,右边大于等于它,并返回其下标 int partition(int a[], int p, int r, int原创 2014-10-15 18:34:45 · 368 阅读 · 0 评论 -
桶排序
#include #include #include int n; struct bucket { int b[11]; int count;//每桶元素的个数 }*pbucket; int cmp(const void *a, const void *b) { return *(int *)a - *(int *)b; } void bucketsort(int a[]) {原创 2015-06-01 11:43:20 · 386 阅读 · 0 评论