diff --git a/Alogrithm/.vs/Alogrithm/v16/.suo b/Alogrithm/.vs/Alogrithm/v16/.suo index 0d6b626..2105ed4 100644 Binary files a/Alogrithm/.vs/Alogrithm/v16/.suo and b/Alogrithm/.vs/Alogrithm/v16/.suo differ diff --git a/Alogrithm/Alogrithm/Alogrithm.vcxproj b/Alogrithm/Alogrithm/Alogrithm.vcxproj index 7a3fa05..13cd0b4 100644 --- a/Alogrithm/Alogrithm/Alogrithm.vcxproj +++ b/Alogrithm/Alogrithm/Alogrithm.vcxproj @@ -157,6 +157,7 @@ + @@ -165,6 +166,7 @@ + @@ -184,6 +186,7 @@ + @@ -192,6 +195,7 @@ + @@ -210,6 +214,7 @@ + diff --git a/Alogrithm/Alogrithm/Alogrithm.vcxproj.filters b/Alogrithm/Alogrithm/Alogrithm.vcxproj.filters index 08d2938..1adf8b7 100644 --- a/Alogrithm/Alogrithm/Alogrithm.vcxproj.filters +++ b/Alogrithm/Alogrithm/Alogrithm.vcxproj.filters @@ -99,6 +99,12 @@ 源文件\src + + 源文件\src + + + 源文件 + @@ -173,6 +179,12 @@ 头文件\include + + 头文件\include + + + 头文件 + @@ -247,5 +259,8 @@ 资源文件\config + + 资源文件\config + \ No newline at end of file diff --git a/Alogrithm/Alogrithm/Alogrithm.vcxproj.user b/Alogrithm/Alogrithm/Alogrithm.vcxproj.user index 88a5509..966b4ff 100644 --- a/Alogrithm/Alogrithm/Alogrithm.vcxproj.user +++ b/Alogrithm/Alogrithm/Alogrithm.vcxproj.user @@ -1,4 +1,6 @@  - + + true + \ No newline at end of file diff --git a/Alogrithm/Alogrithm/config/25_Partition.ini b/Alogrithm/Alogrithm/config/25_Partition.ini new file mode 100644 index 0000000..35e0047 --- /dev/null +++ b/Alogrithm/Alogrithm/config/25_Partition.ini @@ -0,0 +1,28 @@ +[Test1] +Input1=1,4,3,2,5,2 +Input2=3 +Output=1,2,2,4,3,5 +[Test2] +Input1=1 +Input2=1 +Output=1 +[Test3] +Input1= +Input2=0 +Output= +[Test4] +Input1=1,2,3,4,5 +Input2=2 +Output=1,2,3,4,5 +[Test5] +Input1=3,4,5,2,1,3,11111,234,45221,555,61 +Input2=255 +Output=3,4,5,2,1,3,234,61,11111,45221,555 +[Test6] +Input1=2,2,2,2,2,2,2 +Input2=2 +Output=2,2,2,2,2,2,2 +[Test7] +Input1=2021,2,1,15,16,31 +Input2=10 +Output=2,1,2021,15,16,31 \ No newline at end of file diff --git a/Alogrithm/Alogrithm/include/25_Partition.h b/Alogrithm/Alogrithm/include/25_Partition.h new file mode 100644 index 0000000..3af5263 --- /dev/null +++ b/Alogrithm/Alogrithm/include/25_Partition.h @@ -0,0 +1,9 @@ +#pragma once +#include +struct ListNode +{ + int val; + struct ListNode* next; +}; +struct ListNode* Partition(struct ListNode* head, int x); +void CreatListNode(int *arr, int len, struct ListNode* head); \ No newline at end of file diff --git a/Alogrithm/Alogrithm/include/Common.h b/Alogrithm/Alogrithm/include/Common.h new file mode 100644 index 0000000..26ab26d --- /dev/null +++ b/Alogrithm/Alogrithm/include/Common.h @@ -0,0 +1,6 @@ +#pragma once +#include +#include +#include +char* GetAuthor(); +char* GetLanguage(); \ No newline at end of file diff --git a/Alogrithm/Alogrithm/src/25_Partition.cpp b/Alogrithm/Alogrithm/src/25_Partition.cpp new file mode 100644 index 0000000..5b72d04 --- /dev/null +++ b/Alogrithm/Alogrithm/src/25_Partition.cpp @@ -0,0 +1,39 @@ +#include "../include/25_Partition.h" +#include +//Ŀһһضֵ xзָʹС x Ľڵ +// ڴڻ x Ľڵ֮ǰӦÿڵijʼλá +//˼·,ҵÿڵvalضֵxȽ +// һlargeضֵxĽڵ㣻һsmallضֵxСĽڵ +// Ժlargeӵsmallĺ棬smallҪĽ + +struct ListNode* Partition( struct ListNode* head, int x) { + struct ListNode* small = (struct ListNode*)malloc(sizeof(struct ListNode)); + struct ListNode* large = (struct ListNode*)malloc(sizeof(struct ListNode)); + struct ListNode* smallHead = small; //smallͷ + struct ListNode* largeHead = large; //largeͷ + while (NULL != head) { //head + if (head->val < x) { //ѵǰڵֵóxȽ,Сx + small->next = head; //ѵǰڵӵsmall + small = small->next; //smallָһڵ㣬Ϊһڵ׼ + } + else { //x + large->next = head; //ѵǰڵӵlarge + large = large->next; //smallָһڵ㣬Ϊһڵ׼ + } + head = head->next; //ָһڵ + } + large->next = NULL; + small->next = largeHead->next; //largeӵsmall + return smallHead->next; //small +} +//飬ڵ㸳ֵ +void CreatListNode(int *arr, int len, struct ListNode* head) { + head->val = arr[0]; + for (int i = 1; i < len; i++) { + head->next = (struct ListNode*)malloc(sizeof(struct ListNode)); + head = head->next; + head->val = arr[i]; + } + head->next = NULL; + +} \ No newline at end of file diff --git a/Alogrithm/Alogrithm/src/Common.cpp b/Alogrithm/Alogrithm/src/Common.cpp new file mode 100644 index 0000000..278377d --- /dev/null +++ b/Alogrithm/Alogrithm/src/Common.cpp @@ -0,0 +1,11 @@ +#include "../include/Common.h" + +char* GetAuthor() { + char* Author = (char*)malloc(sizeof(char)*10); + Author = "Author:"; + return Author; +} +char* GetLanguage() { + static char Language[] = "Language:C"; + return Language; +} \ No newline at end of file diff --git a/Alogrithm/Alogrithm/src/main.cpp b/Alogrithm/Alogrithm/src/main.cpp index dca5417..80e0845 100644 --- a/Alogrithm/Alogrithm/src/main.cpp +++ b/Alogrithm/Alogrithm/src/main.cpp @@ -1,9 +1,10 @@ -#include -#include"../include/24_LengthOfLongestSubstring.h" - +#include "../include/Common.h" +#include int main() { - char s[] = "lyj18391569527@163.com"; - printf("%d\n", LengthOfLongestSubstring(s)); - + char *Language = GetLanguage(); + char* Author = GetAuthor(); + printf("%*s\n", 40,Author); + printf("%*s\n", 40,Language); + } diff --git a/Alogrithm/UnitTest/UnitTest.cpp b/Alogrithm/UnitTest/UnitTest.cpp index f1acc43..613d2e2 100644 --- a/Alogrithm/UnitTest/UnitTest.cpp +++ b/Alogrithm/UnitTest/UnitTest.cpp @@ -26,7 +26,7 @@ using namespace Microsoft::VisualStudio::CppUnitTestFramework; #define FileName_22 "../Alogrithm/config/22_Rotate.ini" #define FileName_23 "../Alogrithm/config/23_RestoreIpAddresses.ini" #define FileName_24 "../Alogrithm/config/24_LengthOfLongestSubstring.ini" - +#define FileName_25 "../Alogrithm/config/25_Partition.ini" @@ -481,4 +481,31 @@ namespace UnitTest } } }; + TEST_CLASS(UnitTest_25) + { + TEST_METHOD(TestMethode1) + { + char Section_Name[100][10] = { 0 }; + int Section_Count = CalcCount(100, Section_Name, FileName_25); + int input_count = 0, output_count = 0, returnSize = 0; + int* input_value; + int* output_value; + CString input1, input2,output; + for (int i = 0; i < Section_Count; i++) { + GetPrivateProfileString(Section_Name[i], "Input1", " ", input1.GetBuffer(200), 200, FileName_25); + GetPrivateProfileString(Section_Name[i], "Input2", " ", input2.GetBuffer(20), 20, FileName_25); + GetPrivateProfileString(Section_Name[i], "Output", " ", output.GetBuffer(200), 200, FileName_25); + input_value = str_device(input1, &input_count); + output_value = str_device(output, &output_count); + struct ListNode* head = (struct ListNode*)malloc(sizeof(struct ListNode)); + CreatListNode(input_value,input_count,head); + struct ListNode* returnHead = Partition(head, atoi(input2)); + Assert::AreEqual(input_count, output_count); + for (int i = 0; i < input_count; i++) { + Assert::AreEqual(returnHead->val, output_value[i]); + returnHead = returnHead->next; + } + } + } + }; } diff --git a/Alogrithm/UnitTest/pch.h b/Alogrithm/UnitTest/pch.h index dbe2c0c..7700db7 100644 --- a/Alogrithm/UnitTest/pch.h +++ b/Alogrithm/UnitTest/pch.h @@ -37,6 +37,7 @@ #include"../Alogrithm/include/22_Rotate.h" #include"../Alogrithm/include/23_RestoreIpAddresses.h" #include"../Alogrithm/include/24_LengthOfLongestSubstring.h" +#include"../Alogrithm/include/25_Partition.h" int CalcCount(int n, char(*str)[10],const char *FileName);