Archived
1
0

Initial commit

This commit is contained in:
2025-10-24 17:19:46 +08:00
commit acc0c9e220
155 changed files with 77369 additions and 0 deletions

106
CPP3/CPP3.cpp Normal file
View File

@@ -0,0 +1,106 @@
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define RcdType int
#define OK 1
#define OVERFLOW 0
typedef struct {
RcdType* rcd;
int len;
int size;
} RcdList;
int InitRcdList(RcdList& list,int size) {
list.rcd = (RcdType*)malloc((size + 1) * sizeof(RcdType));
list.len = 0;
list.size = size + 1;
if (NULL == list.rcd) return OVERFLOW;
}
void InsertSort(RcdList& list) {
int i, j;
for (i = 1;i < list.len; i++) {
if (list.rcd[i + 1] < list.rcd[i]) {
list.rcd[0] = list.rcd[i + 1];
j = i + 1;
do { j--, list.rcd[j + 1] = list.rcd[j];
} while (list.rcd[0] < list.rcd[j - 1]);
list.rcd[j] = list.rcd[0];
}
}
}
void ShellInsert(RcdList& L, int dk) {
int i, j;
for (i = 1; i < L.len - dk; ++i) {
if (L.rcd[i + dk] < L.rcd[i]) {
L.rcd[0] = L.rcd[i + dk];
j = i + dk;
do {
j--, L.rcd[j + dk] = L.rcd[j];
} while (j - dk > 0 && L.rcd[0] < L.rcd[j - dk]);
L.rcd[j] = L.rcd[0];
}
}
}
void ShellSort(RcdList& L, int d[], int t) {
int k;
for (k = 0; k < t; ++k) ShellInsert(L, d[k]);
}
void PrintList(RcdList list) {
for (int i = 1;i <= list.len;i++) {
printf("%d ", list.rcd[i]);
}
printf("\n");
}
int main()
{
//先十个数据
RcdList bss;
InitRcdList(bss, 10);
for (int i = 1;i <= 11;i++) {
bss.rcd[i] = rand() % 100;
bss.len++;
}
printf("原始:\n");
PrintList(bss);
RcdList bss1 = bss;
InsertSort(bss1);
printf("直接插入排序结果:\n");
PrintList(bss1);
RcdList bss2 = bss;
int d[3] = { 5,3,1 };
ShellSort(bss2, d, 3);
printf("希尔排序结果:\n");
PrintList(bss2);
//生成10000个数据并统计执行时间
RcdList bss3;
InitRcdList(bss3, 100000);
srand(time(NULL)); //以当前时间作为随机数种子
for (int i = 1;i <= 100001;i++) {
bss3.rcd[i] = rand() % 10000;
bss3.len++;
}
RcdList bss4 = bss3;
clock_t start1 = clock();
InsertSort(bss4);
clock_t end1 = clock();
printf("100000个数据直接插入排序时间: %lf 秒 \n", (double)(end1 - start1) / CLOCKS_PER_SEC);
RcdList bss5 = bss3;
int d1[5] = { 5000,2000,1000,500,1 };
clock_t start2 = clock();
ShellSort(bss5, d1, 5);
clock_t end2 = clock();
printf("100000个数据希尔排序时间: %lf 秒 \n", (double)(end2 - start2) / CLOCKS_PER_SEC);
return 0;
}

31
CPP3/CPP3.sln Normal file
View File

@@ -0,0 +1,31 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36603.0 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CPP3", "CPP3.vcxproj", "{BC99F8BF-1E69-4EEA-9052-FD6B5386835F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BC99F8BF-1E69-4EEA-9052-FD6B5386835F}.Debug|x64.ActiveCfg = Debug|x64
{BC99F8BF-1E69-4EEA-9052-FD6B5386835F}.Debug|x64.Build.0 = Debug|x64
{BC99F8BF-1E69-4EEA-9052-FD6B5386835F}.Debug|x86.ActiveCfg = Debug|Win32
{BC99F8BF-1E69-4EEA-9052-FD6B5386835F}.Debug|x86.Build.0 = Debug|Win32
{BC99F8BF-1E69-4EEA-9052-FD6B5386835F}.Release|x64.ActiveCfg = Release|x64
{BC99F8BF-1E69-4EEA-9052-FD6B5386835F}.Release|x64.Build.0 = Release|x64
{BC99F8BF-1E69-4EEA-9052-FD6B5386835F}.Release|x86.ActiveCfg = Release|Win32
{BC99F8BF-1E69-4EEA-9052-FD6B5386835F}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DF835D10-D1E4-40E0-BCEC-28C100B057B2}
EndGlobalSection
EndGlobal

131
CPP3/CPP3.vcxproj Normal file
View File

@@ -0,0 +1,131 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{bc99f8bf-1e69-4eea-9052-fd6b5386835f}</ProjectGuid>
<RootNamespace>CPP3</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="CPP3.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

22
CPP3/CPP3.vcxproj.filters Normal file
View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="源文件">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="头文件">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="资源文件">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="CPP3.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
</Project>