Browse Source

no message

master
linyongji 4 years ago
parent
commit
17bcf23a70
12 changed files with 152 additions and 8 deletions
  1. BIN
      Alogrithm/.vs/Alogrithm/v16/.suo
  2. +5
    -0
      Alogrithm/Alogrithm/Alogrithm.vcxproj
  3. +15
    -0
      Alogrithm/Alogrithm/Alogrithm.vcxproj.filters
  4. +3
    -1
      Alogrithm/Alogrithm/Alogrithm.vcxproj.user
  5. +28
    -0
      Alogrithm/Alogrithm/config/25_Partition.ini
  6. +9
    -0
      Alogrithm/Alogrithm/include/25_Partition.h
  7. +6
    -0
      Alogrithm/Alogrithm/include/Common.h
  8. +39
    -0
      Alogrithm/Alogrithm/src/25_Partition.cpp
  9. +11
    -0
      Alogrithm/Alogrithm/src/Common.cpp
  10. +7
    -6
      Alogrithm/Alogrithm/src/main.cpp
  11. +28
    -1
      Alogrithm/UnitTest/UnitTest.cpp
  12. +1
    -0
      Alogrithm/UnitTest/pch.h

BIN
Alogrithm/.vs/Alogrithm/v16/.suo View File


+ 5
- 0
Alogrithm/Alogrithm/Alogrithm.vcxproj View File

@@ -157,6 +157,7 @@
<ClCompile Include="src\22_Rotate.cpp" />
<ClCompile Include="src\23_RestoreIpAddresses.cpp" />
<ClCompile Include="src\24_LengthOfLongestSubstring.cpp" />
<ClCompile Include="src\25_Partition.cpp" />
<ClCompile Include="src\2_ExcelSheetColumnTitle.cpp" />
<ClCompile Include="src\3_bool IsUgly.cpp" />
<ClCompile Include="src\4_IsPalindrome.cpp" />
@@ -165,6 +166,7 @@
<ClCompile Include="src\7_MaxDepth.cpp" />
<ClCompile Include="src\8_HammingWeight.cpp" />
<ClCompile Include="src\9_AddBinary.cpp" />
<ClCompile Include="src\Common.cpp" />
<ClCompile Include="src\main.cpp" />
</ItemGroup>
<ItemGroup>
@@ -184,6 +186,7 @@
<ClInclude Include="include\22_Rotate.h" />
<ClInclude Include="include\23_RestoreIpAddresses.h" />
<ClInclude Include="include\24_LengthOfLongestSubstring.h" />
<ClInclude Include="include\25_Partition.h" />
<ClInclude Include="include\2_ExcelSheetColumnTitle.h" />
<ClInclude Include="include\3_bool IsUgly.h" />
<ClInclude Include="include\4_IsPalindrome.h" />
@@ -192,6 +195,7 @@
<ClInclude Include="include\7_MaxDepth.h" />
<ClInclude Include="include\8_HammingWeight.h" />
<ClInclude Include="include\9_AddBinary.h" />
<ClInclude Include="include\Common.h" />
</ItemGroup>
<ItemGroup>
<None Include="config\10_BinaryTreePaths.ini" />
@@ -210,6 +214,7 @@
<None Include="config\22_Rotate.ini" />
<None Include="config\23_RestoreIpAddresses.ini" />
<None Include="config\24_LengthOfLongestSubstring.ini" />
<None Include="config\25_Partition.ini" />
<None Include="config\2_ExcelSheetColumnTiTle.ini" />
<None Include="config\3_bool IsUgly.ini" />
<None Include="config\4_IsPalindrome.ini" />


+ 15
- 0
Alogrithm/Alogrithm/Alogrithm.vcxproj.filters View File

@@ -99,6 +99,12 @@
<ClCompile Include="src\24_LengthOfLongestSubstring.cpp">
<Filter>源文件\src</Filter>
</ClCompile>
<ClCompile Include="src\25_Partition.cpp">
<Filter>源文件\src</Filter>
</ClCompile>
<ClCompile Include="src\Common.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\2_ExcelSheetColumnTitle.h">
@@ -173,6 +179,12 @@
<ClInclude Include="include\24_LengthOfLongestSubstring.h">
<Filter>头文件\include</Filter>
</ClInclude>
<ClInclude Include="include\25_Partition.h">
<Filter>头文件\include</Filter>
</ClInclude>
<ClInclude Include="include\Common.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="config\3_bool IsUgly.ini">
@@ -247,5 +259,8 @@
<None Include="config\24_LengthOfLongestSubstring.ini">
<Filter>资源文件\config</Filter>
</None>
<None Include="config\25_Partition.ini">
<Filter>资源文件\config</Filter>
</None>
</ItemGroup>
</Project>

+ 3
- 1
Alogrithm/Alogrithm/Alogrithm.vcxproj.user View File

@@ -1,4 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
<PropertyGroup>
<ShowAllFiles>true</ShowAllFiles>
</PropertyGroup>
</Project>

+ 28
- 0
Alogrithm/Alogrithm/config/25_Partition.ini View File

@@ -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

+ 9
- 0
Alogrithm/Alogrithm/include/25_Partition.h View File

@@ -0,0 +1,9 @@
#pragma once
#include <stdlib.h>
struct ListNode
{
int val;
struct ListNode* next;
};
struct ListNode* Partition(struct ListNode* head, int x);
void CreatListNode(int *arr, int len, struct ListNode* head);

+ 6
- 0
Alogrithm/Alogrithm/include/Common.h View File

@@ -0,0 +1,6 @@
#pragma once
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
char* GetAuthor();
char* GetLanguage();

+ 39
- 0
Alogrithm/Alogrithm/src/25_Partition.cpp View File

@@ -0,0 +1,39 @@
#include "../include/25_Partition.h"
#include <stdio.h>
//题目:给定一个链表和一个特定值 x,对链表进行分隔,使得所有小于 x 的节点
// 都在大于或等于 x 的节点之前。你应当保留两个分区中每个节点的初始相对位置。
//思路:遍历整个链表,找到每个节点的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;

}

+ 11
- 0
Alogrithm/Alogrithm/src/Common.cpp View File

@@ -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;
}

+ 7
- 6
Alogrithm/Alogrithm/src/main.cpp View File

@@ -1,9 +1,10 @@
#include<stdio.h>
#include"../include/24_LengthOfLongestSubstring.h"

#include "../include/Common.h"
#include <stdio.h>
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);

}

+ 28
- 1
Alogrithm/UnitTest/UnitTest.cpp View File

@@ -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;
}
}
}
};
}

+ 1
- 0
Alogrithm/UnitTest/pch.h View File

@@ -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);


Loading…
Cancel
Save