![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
文章平均质量分 53
vshadow
这个作者很懒,什么都没留下…
展开
-
ACM 算法题:Parencodings
对于正常的括号对序列,也就是左括号与右括号的数目是相等的,并且成对。例如(((()()()))),总共有n个括号。 通过两种形式对括号对编码: P序列: P = p1 p2 … pn Pi是第i个右括号之前左括号的数目。 W序列: W = w1 w2 … wn Wi是第i个右括号与之匹配及其包含的左括号的数目。 要求:写一个算法,将括号对的P序列转换成W序列。翻译 2013-03-01 16:39:53 · 841 阅读 · 0 评论 -
由外向内顺时针&逆时针旋转矩阵
代码如下: #include using namespace ::std; #define N 10 int a[N][N]; void InitSeq( int n ) { int value = 1; int i, j; for( i = 0; i < n/2; i++ ) // n/2是圈数 { for( j = i; j < n - i;原创 2013-05-28 21:09:15 · 4009 阅读 · 0 评论 -
数据结构与算法分析C语言版-第10章289页:将递归算法改为时间复杂度为O(n)的非递归算法
#include using namespace ::std; double Eval( int N ) //递归方法 { int i; double Sum; if( N == 0 ) return 1.0; else { Sum = 0.0; for( i = 0; i < N; i++ )原创 2013-05-10 10:16:42 · 812 阅读 · 0 评论 -
两个数组A、B,求在A中出现而不在B中的数(求不相交集)
#include using namespace std; #define M 6 #define N 4 void CompArr( int arr1[], int arr2[] ) { int meet; for( int i = 0; i < M; i++ ) { meet = 0; for( int j = 0; j < N; j++ ) { if( arr原创 2013-04-27 20:54:04 · 2795 阅读 · 0 评论 -
左旋字符串源码
#include using namespace std; void Reverse( char *pBegin, char *pEnd ) { if( pBegin == NULL || pEnd == NULL ) return; while( pBegin < pEnd ) { char tmp = *pBegin; *pBegin = *pEn原创 2013-04-27 09:46:12 · 667 阅读 · 0 评论 -
字符串反转C++实现源码(带测试用例)
将字符串字符顺序反转: #include using namespace std; void Reverse( char *pBegin, char *pEnd ) { if( pBegin == NULL || pEnd == NULL ) return; while( pBegin < pEnd ) { char tmp = *pBegin; *pBegin原创 2013-04-26 09:37:38 · 1508 阅读 · 0 评论 -
优先队列(堆)C++实现源码
堆是一棵完全二叉树,最小元素在根结点上,任意子树也是一个堆。对于堆中的任意一个位置i上的元素,其左儿子在2i位置上,右儿子在2i+1位置上,它的父节点在 2/i 位置上。 堆的插入: 为了保持堆为完全二叉树,在堆的最后一个位置创建空结点,如果空结点的父节点大于要插入的结点,就将父节点移入空结点中,依此类推,直到要插入的结点能放入移空的位置中。 堆的删除(删除根结点,也就是最小的元素): 将原创 2013-04-25 15:50:37 · 1281 阅读 · 0 评论 -
用链表实现栈C++实现源码
头文件: //Stack.h struct node; typedef struct node *Stack; Stack CreateStack(); void Push( int, Stack ); void PrintStack( Stack ); void Pop(Stack); int StackLength( Stack ); 源文件: //Stack原创 2013-04-19 16:21:14 · 1877 阅读 · 0 评论 -
二叉搜索树C++实现源码
二叉搜索树的性质是:对树中的每个结点X,它的左子树的值小于X,它的右子树的值大于X。 BinaryTree.h #include "Utility.h" //typedef struct TreeNode *PtrToNode; typedef struct TreeNode *Position; typedef struct TreeNode *SearchTree; st原创 2013-04-23 16:05:08 · 785 阅读 · 0 评论 -
由内向外顺时针旋转队列&逆时针旋转队列
代码如下: #include using namespace ::std; int max(int n1, int n2) { return n1 > n2 ? n1 : n2; } int abs(int x) { return x > 0 ? x : -x; } int spiral(int x, int y) //根据坐标得出当前值 { int原创 2013-05-28 16:46:47 · 1356 阅读 · 0 评论