摘要: 字符串转换成整形值,能够考虑的异常因素有很多。编写代码之前设计测试用例很有帮助。 1 enum STATUS{STRNULL=0, STREMPTY, STRINVALID, STROVERFLOW, STRVALID}; 2 enum SIGN{NEGATIVE=0, POSITIVE}; 3 enum STATUS status = STRVALID; 4 enum SIGN sign = POSITIVE; 5 int str2int(const char *str) 6 { 7 long long num = 0; 8 9 if (str == NU... 阅读全文
posted @ 2013-09-17 17:02 alpha19881007 阅读(224) 评论(0) 推荐(0) 编辑
摘要: 根据二叉树的先序遍历和中序遍历重建二叉树。 1 #include 2 3 #include 4 5 using namespace std; 6 7 template 8 struct TreeNode 9 { 10 T m_nData; 11 12 TreeNode* m_pLeft; 13 14 TreeNode* m_pRight; 15 16 }; 17 18 19 template 20 TreeNode* ConstructTree(const T* pPreTraval, const T* pInTraval, int... 阅读全文
posted @ 2013-09-12 10:44 alpha19881007 阅读(175) 评论(0) 推荐(0) 编辑
摘要: 异或运算是位运算的一种。我们知道位运算速度很快,同时因其运算的特点,给我们带来不同的解题思路来处理问题。异或运算,可以用来实现两个数的交换,而不必担心越界问题;异或运算可以找出数组中只出现一次的值;异或运算可以找出从一个数组中任意删除的一个值。 1 #include 2 3 using namespace std; 4 5 void main() 6 { 7 //交换a与b 8 int a = 10; 9 int b = 5;10 a = a ^ b;11 b = a ^ b;12 a = a ^ b;13 cout<<a<<","... 阅读全文
posted @ 2013-09-05 23:04 alpha19881007 阅读(303) 评论(0) 推荐(0) 编辑
摘要: 寻找单项链表中间那个元素,如果有两个则取前面一个。 1 #include 2 #include 3 4 using namespace std; 5 6 template 7 struct Node 8 { 9 T m_nData;10 Node *m_pNext;11 };12 13 template14 Node* createList(const T myArray[], const int &n)15 //创建链表16 {17 assert(myArray && n >0);18 Node* pHead = new Node;19 No... 阅读全文
posted @ 2013-09-05 10:37 alpha19881007 阅读(225) 评论(0) 推荐(0) 编辑
摘要: 长度为n的整形数组,找出其中任意n-1个乘积最大的那一组,只能用乘法,不可以用除法。要求对算法时间复杂度和空间复杂度进行分析。#include #include #include #include int ret1Index(const int myArray[], const int n)//返回1个不包含在n-1个因子乘积最大组合中的因子下标{ int negNum = 0;//负数个数 for (int i = 0; i = 0 && myArray[i] abs(myNum)) { ind... 阅读全文
posted @ 2013-09-05 09:29 alpha19881007 阅读(197) 评论(0) 推荐(0) 编辑
摘要: 1 #include 2 #include 3 4 using namespace std; 5 6 template 7 void printArray(T array[],int arrayLen) 8 { 9 if (arrayLen > 1) 10 { 11 cout 22 void randomPerm(T array[],int arrayLen) 23 { 24 if (arrayLen > 1) 25 { 26 T ex; 27 int rand1,rand2; 28 ... 阅读全文
posted @ 2013-08-31 22:08 alpha19881007 阅读(195) 评论(0) 推荐(0) 编辑
摘要: TLD过程{初始化部分: { 初始化数据结构(扫描窗口、随机树FERN结构); 利用第一帧图像和初始BB获得各种正负样本,用这些样本训练一个 分类器。 }重复处理帧序列部分: { ... 阅读全文
posted @ 2013-08-07 20:34 alpha19881007 阅读(461) 评论(0) 推荐(1) 编辑
摘要: 条款32:确定public继承is-a的意义符合你的设计意图ClassPerson;ClassStudent:publicPerson{};Voidstudy(constStudent&s);Voideat(constPerson&p);Personp;Students;eat(p);eat(s);Study(p);Study(s);Public继承代表的是is-a的关系。对于eat()函数,编译器可以将Student对象转型为Person对象,而对于study()函数而言,Person对象不一定是Student对象,因此反过来就行不通。如果想要程序编译通过,可能要进行强制类型 阅读全文
posted @ 2013-08-07 20:21 alpha19881007 阅读(231) 评论(0) 推荐(1) 编辑