摘要: 1 #include "stdafx.h" 2 #include 3 #include 4 #include 5 using namespace std; 6 7 /* 8 旋转数组的最小数字 9 题目:把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转,输入10 一个递增排序的数组的一个旋转。输出旋转数组的最小元素。例如数组{3,4,5,1,2}11 为{1,2,3,4,5}的一个旋转,该数组的最小值为1.12 思路:遍历一遍找最小值.时间复杂度显然是O(n),这个思路显然达不到要求.13 */14 15 int Min(int *arr,int beg,i 阅读全文
posted @ 2014-02-20 23:50 CrazyCode. 阅读(219) 评论(0) 推荐(0) 编辑
摘要: 1 #include "stdafx.h" 2 #include 3 #include 4 #include 5 using namespace std; 6 7 void Swap(int *lhs,int *rhs) 8 { 9 int temp = *lhs;10 *lhs = *rhs;11 *rhs = temp;12 }13 14 int Partition(int* Array,int begin,int end)15 {16 int ran = begin+ rand() % (end-begin+1);//生成一个从begin到end... 阅读全文
posted @ 2014-02-20 14:18 CrazyCode. 阅读(134) 评论(0) 推荐(0) 编辑
摘要: #include "stdafx.h"#include #include #include using namespace std;/* 重建二叉树题目:输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树. 假设输入的前序遍历和中序遍历的结果中都不含重复的数字.例如 输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7,2,1,5,3,8,6}, 则重建出图所示的二叉树并输出它的头结点。二叉树结点的定义如下:*/struct BinaryTreeNode{ int m_nValue; BinaryTreeNode* m_p... 阅读全文
posted @ 2014-02-20 01:18 CrazyCode. 阅读(1494) 评论(0) 推荐(0) 编辑