![](https://img-blog.csdnimg.cn/20201014180756738.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
文章平均质量分 73
One-_-Piece
爱好电脑
展开
-
堆实现优先级队列(算法导论第六章)
与前一篇堆的实现相关。此页代码未经调试! //priority queueint HeapMaximum( int *heap, int heapSize ){ return heap[heapSize - 1];}int HeapExtractMax( int *heap, int heapSize ){ if ( heapSize < 1 ) { cout原创 2013-05-16 11:44:48 · 431 阅读 · 0 评论 -
散列表
转载地址http://blog.csdn.net/yyxaf/article/details/7527878 散列方法不同于顺序查找、二分查找、二叉排序树及B-树上的查找。它不以关键字的比较为基本操作,采用直接寻址技术。在理想情况下,无须任何比较就可以找到待查关键字,查找的期望时间为O(1)。散列表的概念1、散列表设所有可能出现的关键字集合记为U(简称全集)。实际发转载 2013-05-28 22:34:15 · 563 阅读 · 0 评论 -
散列表(哈希表)各种方法实现
本文为散列表(哈希表)的源代码,如若想看算法具体介绍请点击下面链接:http://blog.csdn.net/aytfly/article/details/8986920 /** * @brief Hash Table * @author An * @data 2013.5.28原创 2013-05-29 11:19:43 · 791 阅读 · 0 评论 -
二叉查找树的各种操作源码
/** * @brief Binary Search Tree * @author An * @data 2013.6.1 **/#include #include // start from 0// #define Left( x ) ( 2 *原创 2013-06-03 17:41:40 · 474 阅读 · 0 评论 -
红黑树的创建、插入和删除等源代码
头文件:#ifndef RB_TREE_H#define RB_TREE_H#include #include #include using namespace std;enum RB_COLOR { BLACK, RED };// class RB_Tree;// 树结点class TreeNode{ friend class RB_Tree;public:原创 2013-07-18 10:46:55 · 702 阅读 · 0 评论 -
动态规划——矩阵链相乘
/** * @brief MatrixChainMultiplication Algorithm 15.2 * @author An * @data 2013.8.25 **/#include #include #define N 6using原创 2013-08-25 16:07:59 · 886 阅读 · 0 评论 -
动态规划——最长公共子序列(LCS)
/** * @brief longest common subsequence(LCS) * @author An * @data 2013.8.26 **/#include #include using namespace std;enum D原创 2013-08-26 22:32:21 · 489 阅读 · 0 评论 -
动态规划——装配线调度
/** * @brief Algorithm 15.1 * @author An * @data 2013.8.15 **/#include #define min( x, y ) ( x <= y ? x : y )using namespace原创 2013-08-16 22:06:10 · 584 阅读 · 0 评论 -
动态规划——0-1背包问题
/** * @brief 0_1_Knapsack dynamic programming * @author An * @data 2013.8.28 **//*** @problem * @0-1背包问题: /* 给定n种物品和一个背原创 2013-08-29 20:24:13 · 622 阅读 · 0 评论 -
B树的实现与源代码一
B树的定义假设B树的度为t(t>=2),则B树满足如下要求:(参考算法导论)(1) 每个非根节点至少包含t-1个关键字,t个指向子节点的指针;至多包含2t-1个关键字,2t个指向子女的指针(叶子节点的子女为空)。(2) 节点的所有key按非降序存放,假设节点的关键字分别为K[1], K[2] … K[n], 指向子女的指针分别为P[1], P[2]…P[n+1],其中n为节点关键字原创 2013-09-02 17:50:51 · 1211 阅读 · 0 评论 -
B树的实现与源代码二(删除源代码)
int BTreeMaximum( BNode *x ){ if ( x->leaf ) { return x->key[x->size - 1]; } else { return BTreeMaximum( x->child[x->size] ); }}int BTreeMinimum( BNode *x ){ if ( x->leaf ) { return原创 2013-09-03 12:38:48 · 757 阅读 · 0 评论 -
分治法(算法导论Lec3)
包括一个数的n次方O(lgn),矩阵相乘,矩阵的n次方,斐波纳契的各种方法(运行时间指数,O(n), O(lgn) ) /** * @brief Divide and Conquer, Algorithm lecture3 * @author An * @data 2013.5.14原创 2013-05-14 16:04:07 · 508 阅读 · 0 评论 -
排序及相关三(算法导论PS1-3)
/** * @brief Unimodal Search, Algorithm PS 1-3 * @author An * @data 2013.5.13 **///using namespace std;int unimodalSearch ( i原创 2013-05-13 12:11:43 · 442 阅读 · 0 评论 -
排序及相关一(算法导论二章)
一、插入排序伪代码:INSERTION-SORT (A, n) ⊳ A[1 . . n]for j ← 2 to ndo key ← A[ j]i ← j – 1while i > 0 and A[i] > keydo A[i+1] ← A[i]i ← i – 1A[i+1] = key 代码//insertion sortvoid insertionSort原创 2013-05-10 20:12:31 · 430 阅读 · 0 评论 -
堆排序(算法导论第六章)
T(n) = nlgn /** * @brief Heap Sort * @author An * @data 2013.5.15 **/#include using namespace std;void MaxHeapify ( int *原创 2013-05-16 08:41:43 · 608 阅读 · 0 评论 -
快速排序和随机化快速排序(算法导论第七章)
/** * @brief Quick Sort * @author An * @data 2013.5.17 **/#include #include #include #define random( a, b ) ( rand() % ( b -原创 2013-05-17 15:22:47 · 579 阅读 · 0 评论 -
C/C++产生随机数
C/C++怎样产生随机数:这里要用到的是rand()函数, srand()函数,C语言/C++里没有自带的random(int number)函数。(1) 如果你只要产生随机数而不需要设定范围的话,你只要用rand()就可以了:rand()会返回一随机数值, 范围在0至RAND_MAX 间。RAND_MAX定义在stdlib.h, 其值为2147483647。例如:#includ转载 2013-05-17 12:04:21 · 834 阅读 · 0 评论 -
线性排序之计数排序
要求数的范围0到range,时间复杂度为O(n) /** * @brief counting sort * @author An * @data 2013.5.18 **/int* CountingSort( int *array, int le原创 2013-05-18 11:03:23 · 351 阅读 · 0 评论 -
顺序统计学(算法导论第九章)
找第i小的数 /** * @brief Order Statistics * @author An * @data 2013.5.20 **/#include #include using namespace std;int Partiti原创 2013-05-20 21:25:40 · 497 阅读 · 0 评论 -
栈和队列的实现
/** * @brief Stack and Queue * @author An * @data 2013.5.21 **/#ifndef STACKANDQUEUE_H#define STACKANDQUEUE_H#define stackSize原创 2013-05-21 21:44:36 · 327 阅读 · 0 评论 -
单链表及转置
/** * @brief Linked List * @author An * @data 2013.5.22 **/#ifndef LINKEDLIST_H#define LINKEDLIST_H#include using namespace s原创 2013-05-22 20:42:39 · 701 阅读 · 0 评论 -
二叉树的非递归遍历
二叉树的非递归遍历 二叉树是一种非常重要的数据结构,很多其它数据结构都是基于二叉树的基础演变而来的。对于二叉树,有前序、中序以及后序三种遍历方法。因为树的定义本身就是递归定义,因此采用递归的方法去实现树的三种遍历不仅容易理解而且代码很简洁。而对于树的遍历若采用非递归的方法,就要采用栈去模拟实现。在三种遍历中,前序和中序遍历的非递归算法都很容易实现,非递归后序遍历实现起来相转载 2013-05-23 15:57:02 · 330 阅读 · 0 评论 -
二叉树的初始化及遍历
前序遍历,中序遍历,后序遍历的递归和非递归实现层次遍历的实现 /** * @brief Binary Tree * @author An * @data 2013.5.22 **/#ifndef BINARYTREE_H#define BIN原创 2013-05-23 15:51:47 · 1081 阅读 · 0 评论 -
排序及相关二(算法导论二章,折半)
折半查找,迭代和递归//iterative binary searchint searchBinaryIt (int *array, int val, int low, int high){ while (low <= high) { int middle = (low + high) / 2; if (array[middle] == val) return middl原创 2013-05-10 21:43:13 · 372 阅读 · 0 评论 -
图的遍历(BFS, DFS)源代码
辅助队列的实现:#ifndef QUEUE_H#define QUEUE_H#include "Graph.h"typedef struct{ int *data; int head; int tail; int length; // 现在数据长度 int size; // 总的可存储大小}Queue;void CreateQueue( Queue *Q,原创 2013-09-04 16:30:49 · 1089 阅读 · 0 评论