2013年10月28日

二叉树转双向链表

摘要: 1 void ConvertToList(TreeNode*& root) { 2 TreeNode* left; 3 TreeNode* right; 4 if (root) { 5 left = root->left_; 6 right = root->right_; 7 TreeNode* left_most_right = left; 8 while (left_most_right && left_most_right->right_) { 9 left_most_right = left_mo... 阅读全文

posted @ 2013-10-28 23:44 samules 阅读(208) 评论(0) 推荐(0) 编辑

最大连续子序列和

摘要: 1 int maxsequence3(int a[], int len) 2 { 3 int maxsum, maxhere; 4 maxsum = maxhere = a[0]; //初始化最大和为a【0】 5 for (int i=1; i maxsum) { 11 maxsum = maxhere; //更新最大连续子序列和 12 } 13 } 14 return maxsum; 15 } 阅读全文

posted @ 2013-10-28 19:27 samules 阅读(213) 评论(0) 推荐(0) 编辑

找出一个字符串中第一个只出现一次的字符

摘要: 1 #include 2 using namespace std; 3 4 char lmf(char *pString) 5 { 6 if(!pString) 7 { 8 return 0; 9 } 10 //定义并初始化hash表 11 unsigned int hash[256] = {0}; 12 13 char *pHashKey = pString; 14 //根据字符串,计数!!! 15 while(*pHashKey != '\0') 1... 阅读全文

posted @ 2013-10-28 19:15 samules 阅读(265) 评论(0) 推荐(0) 编辑

二叉树的镜像变换

摘要: 1 #include "stdafx.h" 2 #include 3 using namespace std; 4 5 struct BinaryTreeNode 6 { 7 int m_nValue; 8 BinaryTreeNode *m_pLeft; 9 BinaryTreeNode *m_pRight; 10 }; 11 12 //构造树的镜像 13 void Mirror(BinaryTreeNode *pRoot) 14 { 15 if (pRoot != NULL) 16 { 17 ... 阅读全文

posted @ 2013-10-28 19:11 samules 阅读(251) 评论(0) 推荐(0) 编辑

二叉树的层序遍历(广度优先遍历)

摘要: 1 #include 2 #include 3 using namespace std; 4 5 //树结构 6 struct BTreeNode 7 { 8 int m_nValue; 9 BTreeNode *m_pLeft; 10 BTreeNode *m_Right; 11 }; 12 13 //层序遍历二叉树,即广度优先。 14 void Print(BTreeNode *pNode) 15 { 16 if(!pNode) 17 { 18 return ; 19 ... 阅读全文

posted @ 2013-10-28 19:10 samules 阅读(398) 评论(0) 推荐(0) 编辑

导航