这是一个将项目制作成dll的参考工程,关于细节方面,请转到我的博客详细参考,谢谢
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2015-12-29 17:03 MyInterviewQuestion
目录 0 2015-12-28 16:31 MyInterviewQuestion.vs
目录 0 2015-12-28 16:31 MyInterviewQuestion.vsMyInterviewQuestion
目录 0 2015-12-28 16:31 MyInterviewQuestion.vsMyInterviewQuestionv14
文件 92160 2015-12-29 17:03 MyInterviewQuestion.vsMyInterviewQuestionv14.suo
目录 0 2015-12-29 15:16 MyInterviewQuestionConstructBinaryTree
文件 6226 2015-12-29 16:31 MyInterviewQuestionConstructBinaryTreeConstructBinaryTree.vcxproj
文件 959 2015-12-28 23:07 MyInterviewQuestionConstructBinaryTreeConstructBinaryTree.vcxproj.filters
文件 1912 2015-12-29 15:16 MyInterviewQuestionConstructBinaryTreeconstrutbinarytree.cpp
目录 0 2015-12-29 16:31 MyInterviewQuestionConstructBinaryTreeDebug
目录 0 2015-12-29 16:31 MyInterviewQuestionConstructBinaryTreeDebugConstruc.C696DF69.tlog
文件 708 2015-12-29 16:24 MyInterviewQuestionConstructBinaryTreeDebugConstruc.C696DF69.tlogCL.command.1.tlog
文件 12440 2015-12-29 16:24 MyInterviewQuestionConstructBinaryTreeDebugConstruc.C696DF69.tlogCL.read.1.tlog
文件 708 2015-12-29 16:24 MyInterviewQuestionConstructBinaryTreeDebugConstruc.C696DF69.tlogCL.write.1.tlog
文件 179 2015-12-29 16:31 MyInterviewQuestionConstructBinaryTreeDebugConstruc.C696DF69.tlogConstructBinaryTree.lastbuildstate
文件 1606 2015-12-29 16:31 MyInterviewQuestionConstructBinaryTreeDebugConstruc.C696DF69.tloglink.command.1.tlog
文件 3280 2015-12-29 16:31 MyInterviewQuestionConstructBinaryTreeDebugConstruc.C696DF69.tloglink.read.1.tlog
文件 790 2015-12-29 16:31 MyInterviewQuestionConstructBinaryTreeDebugConstruc.C696DF69.tloglink.write.1.tlog
文件 1259 2015-12-29 16:31 MyInterviewQuestionConstructBinaryTreeDebugConstructBinaryTree.log
文件 671 2015-12-29 16:31 MyInterviewQuestionConstructBinaryTreeDebugConstructBinaryTree.vcxprojResolveAssemblyReference.cache
文件 29604 2015-12-29 16:24 MyInterviewQuestionConstructBinaryTreeDebugconstrutbinarytree.obj
文件 322560 2015-12-29 16:24 MyInterviewQuestionConstructBinaryTreeDebugvc140.idb
文件 356352 2015-12-29 16:24 MyInterviewQuestionConstructBinaryTreeDebugvc140.pdb
目录 0 2015-12-29 16:31 MyInterviewQuestionDebug
文件 40960 2015-12-29 16:31 MyInterviewQuestionDebugConstructBinaryTree.exe
文件 328340 2015-12-29 16:31 MyInterviewQuestionDebugConstructBinaryTree.ilk
文件 913408 2015-12-29 16:31 MyInterviewQuestionDebugConstructBinaryTree.pdb
文件 36352 2015-12-29 16:37 MyInterviewQuestionDebugUtilities.dll
文件 1142 2015-12-29 16:29 MyInterviewQuestionDebugUtilities.exp
文件 250564 2015-12-29 16:37 MyInterviewQuestionDebugUtilities.ilk
文件 2504 2015-12-29 16:29 MyInterviewQuestionDebugUtilities.lib
............此处省略32个文件信息
#include
#include
#include “..UtilitiesBinaryTree.h“
using namespace std;
BinaryTreeNode* ConstructCore(int* startPreorder int* endPreorder int* startInorder int* endInorder);
BinaryTreeNode* Construct(int* preorder int* inorder int length)
{
if (preorder == NULL || inorder == NULL || length <= 0)
return NULL;
return ConstructCore(preorder preorder + length - 1
inorder inorder + length - 1);
}
BinaryTreeNode* ConstructCore(int* startPreorder int* endPreorder
int* startInorder int* endInorder)
{
int rootValue = startPreorder[0];
BinaryTreeNode* root = new BinaryTreeNode();
root->m_nValue = rootValue;
root->m_pLeft = root->m_pRight = NULL;
if (startPreorder == endPreorder) {
if (startInorder == endInorder && *startPreorder == *startInorder)
return root;
else
throw exception(“Invalid Input“);
}
//在中序遍历中找到根节点的值
//cout <<“*startInorder“ <<*startInorder << endl;
int* rootInorder = startInorder;
while (rootInorder <= endInorder && *rootInorder != rootValue)
++rootInorder;
if (rootInorder == endInorder && *rootInorder != rootValue)
throw exception(“Invalid Input“);
int leftLength = rootInorder - startInorder;
int* leftPreorderEnd = startPreorder + leftLength;
if (leftLength > 0)
root->m_pLeft = ConstructCore(startPreorder + 1 leftPreorderEnd
startInorder rootInorder - 1);
if (leftLength < endPreorder - startPreorder)
root->m_pRight = ConstructCore(leftPreorderEnd + 1 endPreorder
rootInorder + 1 endInorder);
return root;
}
int main()
{
const int length = 8;
int preOrderArray[length] = { 12473568 };
int inOrderArray[length] = { 47215386 };
BinaryTreeNode* root = Construct(preOrderArray inOrderArray length);
//PrintPreOrder(root);
PrintTree(root);
DestroyTree(root);
int a;
cin >> a;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2015-12-29 17:03 MyInterviewQuestion
目录 0 2015-12-28 16:31 MyInterviewQuestion.vs
目录 0 2015-12-28 16:31 MyInterviewQuestion.vsMyInterviewQuestion
目录 0 2015-12-28 16:31 MyInterviewQuestion.vsMyInterviewQuestionv14
文件 92160 2015-12-29 17:03 MyInterviewQuestion.vsMyInterviewQuestionv14.suo
目录 0 2015-12-29 15:16 MyInterviewQuestionConstructBinaryTree
文件 6226 2015-12-29 16:31 MyInterviewQuestionConstructBinaryTreeConstructBinaryTree.vcxproj
文件 959 2015-12-28 23:07 MyInterviewQuestionConstructBinaryTreeConstructBinaryTree.vcxproj.filters
文件 1912 2015-12-29 15:16 MyInterviewQuestionConstructBinaryTreeconstrutbinarytree.cpp
目录 0 2015-12-29 16:31 MyInterviewQuestionConstructBinaryTreeDebug
目录 0 2015-12-29 16:31 MyInterviewQuestionConstructBinaryTreeDebugConstruc.C696DF69.tlog
文件 708 2015-12-29 16:24 MyInterviewQuestionConstructBinaryTreeDebugConstruc.C696DF69.tlogCL.command.1.tlog
文件 12440 2015-12-29 16:24 MyInterviewQuestionConstructBinaryTreeDebugConstruc.C696DF69.tlogCL.read.1.tlog
文件 708 2015-12-29 16:24 MyInterviewQuestionConstructBinaryTreeDebugConstruc.C696DF69.tlogCL.write.1.tlog
文件 179 2015-12-29 16:31 MyInterviewQuestionConstructBinaryTreeDebugConstruc.C696DF69.tlogConstructBinaryTree.lastbuildstate
文件 1606 2015-12-29 16:31 MyInterviewQuestionConstructBinaryTreeDebugConstruc.C696DF69.tlogli
文件 3280 2015-12-29 16:31 MyInterviewQuestionConstructBinaryTreeDebugConstruc.C696DF69.tlogli
文件 790 2015-12-29 16:31 MyInterviewQuestionConstructBinaryTreeDebugConstruc.C696DF69.tlogli
文件 1259 2015-12-29 16:31 MyInterviewQuestionConstructBinaryTreeDebugConstructBinaryTree.log
文件 671 2015-12-29 16:31 MyInterviewQuestionConstructBinaryTreeDebugConstructBinaryTree.vcxprojResolveAssemblyReference.cache
文件 29604 2015-12-29 16:24 MyInterviewQuestionConstructBinaryTreeDebugconstrutbinarytree.obj
文件 322560 2015-12-29 16:24 MyInterviewQuestionConstructBinaryTreeDebugvc140.idb
文件 356352 2015-12-29 16:24 MyInterviewQuestionConstructBinaryTreeDebugvc140.pdb
目录 0 2015-12-29 16:31 MyInterviewQuestionDebug
文件 40960 2015-12-29 16:31 MyInterviewQuestionDebugConstructBinaryTree.exe
文件 328340 2015-12-29 16:31 MyInterviewQuestionDebugConstructBinaryTree.ilk
文件 913408 2015-12-29 16:31 MyInterviewQuestionDebugConstructBinaryTree.pdb
文件 36352 2015-12-29 16:37 MyInterviewQuestionDebugUtilities.dll
文件 1142 2015-12-29 16:29 MyInterviewQuestionDebugUtilities.exp
文件 250564 2015-12-29 16:37 MyInterviewQuestionDebugUtilities.ilk
文件 2504 2015-12-29 16:29 MyInterviewQuestionDebugUtilities.lib
............此处省略32个文件信息
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)