摘要: 输入一个英文句子,翻转句子中的单词顺序,但单词内的字符顺序不变。如“I am a student." 则输出“student. a am I"void Reverse(char* pBegin, char* pEnd){ if( pBegin == NULL || pEnd == NULL) return; while( pBegin < pEnd) { char temp = *pBegin; *pBegin = *pEnd; *pEnd = temp; pBegin++; pEnd--; ... 阅读全文
posted @ 2013-03-08 21:01 没离开过 阅读(114) 评论(0) 推荐(0) 编辑
摘要: 输入一个递增排序的数组和一个数字是S,在数组中查找两个数,使得它们的和正好是S。bool FindNumbersWithSum(int data[], int length, int sum, int* num1, int* num2){ bool found = false; if( length < 1 || num1 == NULL || num2 == NULL) return found; int ahead= length-1; int behind = 0; while(ahead > behind) { long... 阅读全文
posted @ 2013-03-08 20:41 没离开过 阅读(92) 评论(0) 推荐(0) 编辑
摘要: 如果某二叉树中的任意节点的左右子树的深度相差不超过1,那么它就是一棵平衡二叉树。struct BinaryTreeNode { int value; BinaryTreeNode* p_left; BinaryTreeNode* p_right;};bool IsBalanced(BinaryTreeNode* pRoot, int* pDepth){ if( pRoot == NULL) { *pDepth = 0; return true; } int left,right; if(IsBalanced(pRoot... 阅读全文
posted @ 2013-03-08 20:19 没离开过 阅读(125) 评论(0) 推荐(0) 编辑
摘要: 1.字符串长度:${#string}expr length $stringexpr "$string":'.*'这三种方法都可以。2.从字符串开始的位置匹配字串的长度expr match "$string" '$substring'expr "$string" : '$substring'$substring 是一个正则表达式3.匹配到子串的第一个字符的位置expr index $string $substring4.提取子串${string:position}${string:posi 阅读全文
posted @ 2013-03-08 16:22 没离开过 阅读(152) 评论(0) 推荐(0) 编辑