@@ -116,5 +116,5 @@ Alogrithm/.vs/Alogrithm/v16/ipch/AutoPCH/27a527fda8b54c6b/9_ADDBINARY.ipch | |||||
Alogrithm/.vs/Alogrithm/v16/ipch/AutoPCH/d00489e06883ba57/9_ ADDBINARY.ipch | Alogrithm/.vs/Alogrithm/v16/ipch/AutoPCH/d00489e06883ba57/9_ ADDBINARY.ipch | ||||
Alogrithm/TestResults/dc42f77d-a2f7-41a9-8b8c-1ee3f1a82eb9/林_MI-1 2021-01-18 14_12_23.coverage | Alogrithm/TestResults/dc42f77d-a2f7-41a9-8b8c-1ee3f1a82eb9/林_MI-1 2021-01-18 14_12_23.coverage | ||||
Alogrithm/.vs/Alogrithm/v16/ipch/AutoPCH/86fa7a487ad3f37c/10_BINARYTREEPATHS.ipch | Alogrithm/.vs/Alogrithm/v16/ipch/AutoPCH/86fa7a487ad3f37c/10_BINARYTREEPATHS.ipch | ||||
Alogrithm/.vs/Alogrithm/v16/TestStore/3/003.testlog | |||||
Alogrithm/Alogrithm/Debug/10_BinaryTreePaths.obj | Alogrithm/Alogrithm/Debug/10_BinaryTreePaths.obj | ||||
Alogrithm/.vs/Alogrithm/v16/TestStore/3/003.testlog |
@@ -86,8 +86,8 @@ | |||||
<ClCompile> | <ClCompile> | ||||
<WarningLevel>Level3</WarningLevel> | <WarningLevel>Level3</WarningLevel> | ||||
<SDLCheck>true</SDLCheck> | <SDLCheck>true</SDLCheck> | ||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||||
<ConformanceMode>true</ConformanceMode> | |||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||||
<ConformanceMode>false</ConformanceMode> | |||||
</ClCompile> | </ClCompile> | ||||
<Link> | <Link> | ||||
<SubSystem>Console</SubSystem> | <SubSystem>Console</SubSystem> | ||||
@@ -140,6 +140,7 @@ | |||||
</Link> | </Link> | ||||
</ItemDefinitionGroup> | </ItemDefinitionGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
<ClCompile Include="src\10_BinaryTreePaths.cpp" /> | |||||
<ClCompile Include="src\1_ContainsNearbyDuplicate.cpp" /> | <ClCompile Include="src\1_ContainsNearbyDuplicate.cpp" /> | ||||
<ClCompile Include="src\2_ExcelSheetColumnTitle.cpp" /> | <ClCompile Include="src\2_ExcelSheetColumnTitle.cpp" /> | ||||
<ClCompile Include="src\3_bool IsUgly.cpp" /> | <ClCompile Include="src\3_bool IsUgly.cpp" /> | ||||
@@ -152,6 +153,7 @@ | |||||
<ClCompile Include="src\main.cpp" /> | <ClCompile Include="src\main.cpp" /> | ||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
<ClInclude Include="include\10_BinaryTreePaths.h" /> | |||||
<ClInclude Include="include\1_ContainsNearbyDuplicate.h" /> | <ClInclude Include="include\1_ContainsNearbyDuplicate.h" /> | ||||
<ClInclude Include="include\2_ExcelSheetColumnTitle.h" /> | <ClInclude Include="include\2_ExcelSheetColumnTitle.h" /> | ||||
<ClInclude Include="include\3_bool IsUgly.h" /> | <ClInclude Include="include\3_bool IsUgly.h" /> | ||||
@@ -163,6 +165,7 @@ | |||||
<ClInclude Include="include\9_AddBinary.h" /> | <ClInclude Include="include\9_AddBinary.h" /> | ||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
<None Include="config\10_BinaryTreePaths.ini" /> | |||||
<None Include="config\1_ContainsNearbyDuplicate.ini" /> | <None Include="config\1_ContainsNearbyDuplicate.ini" /> | ||||
<None Include="config\2_ExcelSheetColumnTiTle.ini" /> | <None Include="config\2_ExcelSheetColumnTiTle.ini" /> | ||||
<None Include="config\3_bool IsUgly.ini" /> | <None Include="config\3_bool IsUgly.ini" /> | ||||
@@ -54,6 +54,9 @@ | |||||
<ClCompile Include="src\9_AddBinary.cpp"> | <ClCompile Include="src\9_AddBinary.cpp"> | ||||
<Filter>源文件\src</Filter> | <Filter>源文件\src</Filter> | ||||
</ClCompile> | </ClCompile> | ||||
<ClCompile Include="src\10_BinaryTreePaths.cpp"> | |||||
<Filter>源文件\src</Filter> | |||||
</ClCompile> | |||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
<ClInclude Include="include\2_ExcelSheetColumnTitle.h"> | <ClInclude Include="include\2_ExcelSheetColumnTitle.h"> | ||||
@@ -83,6 +86,9 @@ | |||||
<ClInclude Include="include\9_AddBinary.h"> | <ClInclude Include="include\9_AddBinary.h"> | ||||
<Filter>头文件\include</Filter> | <Filter>头文件\include</Filter> | ||||
</ClInclude> | </ClInclude> | ||||
<ClInclude Include="include\10_BinaryTreePaths.h"> | |||||
<Filter>头文件</Filter> | |||||
</ClInclude> | |||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
<None Include="config\3_bool IsUgly.ini"> | <None Include="config\3_bool IsUgly.ini"> | ||||
@@ -112,5 +118,8 @@ | |||||
<None Include="config\9_AddBinary.ini"> | <None Include="config\9_AddBinary.ini"> | ||||
<Filter>资源文件\config</Filter> | <Filter>资源文件\config</Filter> | ||||
</None> | </None> | ||||
<None Include="config\10_BinaryTreePaths.ini"> | |||||
<Filter>资源文件\config</Filter> | |||||
</None> | |||||
</ItemGroup> | </ItemGroup> | ||||
</Project> | </Project> |
@@ -0,0 +1,19 @@ | |||||
[Test1] | |||||
Input=1,2,3,NULL,5 | |||||
Output=1->2->5,1->3 | |||||
[Test2] | |||||
Input=1,2,3,NULL,4,5 | |||||
Output=1->2->4,1->3->5 | |||||
[Test3] | |||||
input=1,0,0,2,NULL,NULL,0 | |||||
output=1->0->2,1->0->0 | |||||
[Test4] | |||||
input= | |||||
output= | |||||
[Test5] | |||||
input=4,3,1,NULL,2,6,8 | |||||
output=4->3->2,4->1->6,4->1->8 | |||||
[Test6] | |||||
input=1,3,5,7,NULL,2,9,NULL,2 | |||||
output=1->3->7->2,1->5->2,1->5->9 | |||||
@@ -0,0 +1,17 @@ | |||||
#pragma once | |||||
#include <atlstr.h> | |||||
struct TreeNode3 | |||||
{ | |||||
int val; | |||||
struct TreeNode3* left; | |||||
struct TreeNode3* right; | |||||
}; | |||||
void CreatBitTreeNode3(char str[][50], int return_count, TreeNode3* cur, int curIndex); | |||||
TreeNode3* CreatBitTree3(char str[][50], int return_count); | |||||
void get_path(char** array, struct TreeNode3* root, int* returnSize, int* buf, int local); | |||||
char** binaryTreePaths(struct TreeNode3* root, int* returnSize); | |||||
void free_tree3(TreeNode3* T); |
@@ -0,0 +1,89 @@ | |||||
#include "../include/10_BinaryTreePaths.h" | |||||
void CreatBitTreeNode3(char str[][50], int return_count, TreeNode3* cur, int curIndex) | |||||
{ | |||||
if (str == NULL || return_count <= 0 || cur == NULL || curIndex >= return_count || curIndex < 0) { | |||||
return; | |||||
} | |||||
int last = return_count - 1; | |||||
if ((2 * curIndex + 1 <= last) && strcmp(str[2 * curIndex + 1], "NULL")) { | |||||
cur->left = (TreeNode3*)malloc(sizeof(TreeNode3)); | |||||
if (NULL == cur->left) { | |||||
return; | |||||
} | |||||
cur->left->val = _ttoi(str[2 * curIndex + 1]); | |||||
} | |||||
else { | |||||
cur->left = NULL; | |||||
} | |||||
if ((2 * curIndex + 2 <= last) && strcmp(str[2 * curIndex + 2], "NULL")) { | |||||
cur->right = (TreeNode3*)malloc(sizeof(TreeNode3)); | |||||
if (NULL == cur->right) { | |||||
return; | |||||
} | |||||
cur->right->val = _ttoi(str[2 * curIndex + 2]); | |||||
} | |||||
else { | |||||
cur->right = NULL; | |||||
} | |||||
CreatBitTreeNode3(str, return_count, cur->left, 2 * curIndex + 1); | |||||
CreatBitTreeNode3(str, return_count, cur->right, 2 * curIndex + 2); | |||||
} | |||||
TreeNode3* CreatBitTree3(char str[][50], int return_count) | |||||
{ | |||||
if (str == NULL || return_count <= 0) { | |||||
return NULL; | |||||
} | |||||
TreeNode3* head = (TreeNode3*)malloc(sizeof(TreeNode3)); | |||||
if (NULL == head) { | |||||
return NULL; | |||||
} | |||||
head->val = _ttoi(str[0]); | |||||
CreatBitTreeNode3(str, return_count, head, 0); | |||||
return head; | |||||
} | |||||
void get_path(char** array, struct TreeNode3* root, int* returnSize, int* buf, int local) | |||||
{ | |||||
if (NULL == root) { | |||||
return; | |||||
} | |||||
if (!root->left && !root->right) { | |||||
char* str = (char*)malloc(1024); | |||||
int len = 0; | |||||
for (int i = 0; i < local; i++) | |||||
{ | |||||
len += sprintf(str + len, "%d->", buf[i]); | |||||
} | |||||
sprintf(str + len, "%d", root->val); | |||||
array[(*returnSize)++] = str; | |||||
} | |||||
else { | |||||
buf[local++] = root->val; | |||||
get_path(array, root->left, returnSize, buf, local); | |||||
get_path(array, root->right, returnSize, buf, local); | |||||
} | |||||
} | |||||
char** binaryTreePaths(struct TreeNode3* root, int* returnSize) { | |||||
char** ret = (char**)malloc(sizeof(char*) * 1024);//定义一个二级指针,作为返回值返回二维字符串数组 | |||||
*returnSize = 0;//用来保存二维字符串数组的元素个数 | |||||
int buf[1024] = { 0 };//用来接收缓冲 | |||||
get_path(ret, root, returnSize, buf, 0); | |||||
return ret; | |||||
} | |||||
void free_tree3(TreeNode3* T)//后序释放 | |||||
{ | |||||
if (!T) { | |||||
return; | |||||
} | |||||
if (T->left) { | |||||
free_tree3(T->left); | |||||
} | |||||
if (T->right) { | |||||
free_tree3(T->right); | |||||
} | |||||
if (T) { | |||||
free(T); | |||||
T = NULL; | |||||
} | |||||
} |
@@ -1,8 +1,8 @@ | |||||
#include "../include/2_ExcelSheetColumnTitle.h" | |||||
#include "../include/3_bool IsUgly.h" | |||||
int main() | int main() | ||||
{ | { | ||||
//ExcelSheetColumnTitle(10); | |||||
//printf("%d\n", IsUgly(6)); | |||||
return 0; | return 0; | ||||
} | } |
@@ -11,6 +11,7 @@ using namespace Microsoft::VisualStudio::CppUnitTestFramework; | |||||
#define FileName_7 "../Alogrithm/config/7_MaxDepth.ini" | #define FileName_7 "../Alogrithm/config/7_MaxDepth.ini" | ||||
#define FileName_8 "../Alogrithm/config/8_HammingWeight.ini" | #define FileName_8 "../Alogrithm/config/8_HammingWeight.ini" | ||||
#define FileName_9 "../Alogrithm/config/9_AddBinary.ini" | #define FileName_9 "../Alogrithm/config/9_AddBinary.ini" | ||||
#define FileName_10 "../Alogrithm/config/10_BinaryTreePaths.ini" | |||||
namespace UnitTest | namespace UnitTest | ||||
@@ -170,4 +171,35 @@ namespace UnitTest | |||||
} | } | ||||
} | } | ||||
}; | }; | ||||
TEST_CLASS(UnitTest_10) | |||||
{ | |||||
TEST_METHOD(TestMethode1) | |||||
{ | |||||
char Section_Name[100][10] = { 0 }; | |||||
int Section_Count = CalcCount(100, Section_Name, FileName_10); | |||||
CString Na, nExpect; | |||||
for (int i = 0; i < Section_Count; i++) { | |||||
GetPrivateProfileString(Section_Name[i], "input", " ", Na.GetBuffer(200), 200, FileName_10); | |||||
GetPrivateProfileString(Section_Name[i], "output", " ", nExpect.GetBuffer(500), 500, FileName_10); | |||||
char return_str[100][50] = { 0 }; | |||||
int return_count = str_device2(Na, return_str); | |||||
TreeNode3* root = CreatBitTree3(return_str, return_count); | |||||
int returnSize = 0; | |||||
char** returnStr=NULL; | |||||
returnStr = binaryTreePaths(root, &returnSize); | |||||
char nReal[500] = { 0 }; | |||||
for (int i = 0; i < returnSize; i++) | |||||
{ | |||||
strcat(nReal, returnStr[i]); | |||||
if (i != (returnSize - 1)) | |||||
{ | |||||
nReal[strlen(nReal)] = ','; | |||||
} | |||||
} | |||||
Assert::AreEqual(nReal,nExpect); | |||||
free_tree3(root); | |||||
} | |||||
} | |||||
}; | |||||
} | } |
@@ -103,7 +103,7 @@ | |||||
<SubSystem>Windows</SubSystem> | <SubSystem>Windows</SubSystem> | ||||
<AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | <AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | ||||
<GenerateDebugInformation>DebugFull</GenerateDebugInformation> | <GenerateDebugInformation>DebugFull</GenerateDebugInformation> | ||||
<AdditionalDependencies>../Alogrithm/Debug/1_ContainsNearbyDuplicate.obj;../Alogrithm/Debug/2_ExcelSheetColumnTitle.obj;../Alogrithm/Debug/3_bool IsUgly.obj;../Alogrithm/Debug/4_IsPalindrome.obj;../Alogrithm/Debug/5_MinDepth.obj;../Alogrithm/Debug/6_ContainsDuplicate.obj;../Alogrithm/Debug/7_MaxDepth.obj;../Alogrithm/Debug/8_HammingWeight.obj;../Alogrithm/Debug/9_AddBinary.obj;%(AdditionalDependencies)</AdditionalDependencies> | |||||
<AdditionalDependencies>../Alogrithm/Debug/1_ContainsNearbyDuplicate.obj;../Alogrithm/Debug/2_ExcelSheetColumnTitle.obj;../Alogrithm/Debug/3_bool IsUgly.obj;../Alogrithm/Debug/4_IsPalindrome.obj;../Alogrithm/Debug/5_MinDepth.obj;../Alogrithm/Debug/6_ContainsDuplicate.obj;../Alogrithm/Debug/7_MaxDepth.obj;../Alogrithm/Debug/8_HammingWeight.obj;../Alogrithm/Debug/9_AddBinary.obj;../Alogrithm/Debug/10_BinaryTreePaths.obj;%(AdditionalDependencies)</AdditionalDependencies> | |||||
</Link> | </Link> | ||||
</ItemDefinitionGroup> | </ItemDefinitionGroup> | ||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||||
@@ -22,6 +22,7 @@ | |||||
#include"../Alogrithm/include/7_MaxDepth.h" | #include"../Alogrithm/include/7_MaxDepth.h" | ||||
#include"../Alogrithm/include/8_HammingWeight.h" | #include"../Alogrithm/include/8_HammingWeight.h" | ||||
#include"../Alogrithm/include/9_AddBinary.h" | #include"../Alogrithm/include/9_AddBinary.h" | ||||
#include"../Alogrithm/include/10_BinaryTreePaths.h" | |||||
int CalcCount(int n, char(*str)[10],const char *FileName); | int CalcCount(int n, char(*str)[10],const char *FileName); | ||||