提交 5d7038a4 编写于 作者: 御承扬

添加项目文件。

上级 3f2bfa02

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.645
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "排序", "排序\排序.vcxproj", "{E947DC8F-4FEC-4885-B082-EF09967AA4A2}"
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
{E947DC8F-4FEC-4885-B082-EF09967AA4A2}.Debug|x64.ActiveCfg = Debug|x64
{E947DC8F-4FEC-4885-B082-EF09967AA4A2}.Debug|x64.Build.0 = Debug|x64
{E947DC8F-4FEC-4885-B082-EF09967AA4A2}.Debug|x86.ActiveCfg = Debug|Win32
{E947DC8F-4FEC-4885-B082-EF09967AA4A2}.Debug|x86.Build.0 = Debug|Win32
{E947DC8F-4FEC-4885-B082-EF09967AA4A2}.Release|x64.ActiveCfg = Release|x64
{E947DC8F-4FEC-4885-B082-EF09967AA4A2}.Release|x64.Build.0 = Release|x64
{E947DC8F-4FEC-4885-B082-EF09967AA4A2}.Release|x86.ActiveCfg = Release|Win32
{E947DC8F-4FEC-4885-B082-EF09967AA4A2}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E5CD000E-B6EC-4791-A30A-E7B645E37413}
EndGlobalSection
EndGlobal
// pch.cpp: 与预编译标头对应的源文件;编译成功所必需的
#include "pch.h"
// 一般情况下,忽略此文件,但如果你使用的是预编译标头,请保留它。
// 入门提示:
// 1. 使用解决方案资源管理器窗口添加/管理文件
// 2. 使用团队资源管理器窗口连接到源代码管理
// 3. 使用输出窗口查看生成输出和其他消息
// 4. 使用错误列表窗口查看错误
// 5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目
// 6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件
#ifndef PCH_H
#define PCH_H
// TODO: 添加要在此处预编译的标头
#endif //PCH_H
// 排序.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include "pch.h"
#include <iostream>
using namespace std;
//数组输出
void dispArray(int a[], int len)
{
int i;
for (i = 0; i < len; i++)
{
cout << a[i] << " ";
}
cout << endl;
}
//直接插入排序
void directInsertionSort(int num[], int len)
{
int *a = new int[len];
int i, j, key;
for (i = 0; i < len; i++)
a[i] = num[i];
for (i = 1; i < len; i++)
{
if (a[i] < a[i - 1])
{
key = a[i];
a[i] = a[i - 1];
for (j = i - 1; key < a[j]; j--)
a[j + 1] = a[j];
a[j + 1] = key;
}
}
dispArray(a, len);
}
//希尔排序
void shellSort(int num[], int len)
{
int *a = new int[len];
int i, j, key;
for (i = 0; i < len; i++)
a[i] = num[i];
key = len;
do
{
key = key / 3 + 1;
for (i = key; i < len; i++)
{
if (a[i] > a[i - key])
{
int temp = a[i];
for (j = i - key; j >= 0 && temp > a[j]; j = j - key)
a[j + key] = a[j];
a[j + key] = temp;
}
}
} while (key > 1);
dispArray(a, len);
}
//冒泡排序
void bubbleSort(int num[], int len)
{
int *a = new int[len];
int i, j, m, key;
for (i = 0; i < len; i++)
a[i] = num[i];
m = len-1;
key = 1;
while (m >= 0 && key == 1)
{
key = 0;
for (j = 0; j < m; j++)
{
if (a[j] > a[j + 1])
{
key = 1;
int temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
}
m--;
}
dispArray(a, len);
}
//快速排序
void quickSort(int a[], int low, int len)
{
int i, j, m;
if (low < len)
{
i = low;
j = len;
m = a[low];
while (i < j)
{
while (i < j&&a[j] < m)
j--;
if (i < j)
a[i++] = a[j];
while (i < j&&a[i] >= m)
i++;
if (i < j)
a[j--] = a[i];
}
a[i] = m;
quickSort(a, low,i-1);
quickSort(a, i+1,len);
}
}
//堆排序
void Adjust(int a[], int len, int index)
{
int left = 2 * index + 1;
int right = 2 * index + 2;
int maxIndex = index; // a[left]、a[right]和a[maxIndex]三个数中最大数的下标
if (left<len&&a[left]>a[maxIndex]) maxIndex = left;
if (right<len&&a[right]>a[maxIndex]) maxIndex = right;
if (maxIndex != index) // 如果 maxIndex 有更新
{
swap(a[maxIndex], a[index]);
Adjust(a, len, maxIndex); // 递归调整其他不满足堆性质的部分
}
}
void heapSort(int num[], int len)
{
int *a = new int[len];
int i, j;
for (i = 0; i < len; i++)
a[i] = num[i];
for (i = len / 2 - 1; i >= 0; i--) //对每一个非叶子节点进行堆调整(从最后一个开始)
{
Adjust(a, len, i);
}
for (j = len - 1; j >= 1; j--)
{
swap(a[0], a[j]); // 将当前最大的放置到数组末尾
Adjust(a, j, 0); // 将未完成排序的部分继续进行堆排序
}
dispArray(a, len);
}
//选择排序
void selectSort(int num[], int len)
{
int *a = new int[len];
int i, j;
for (i = 0; i < len; i++)
a[i] = num[i];
for (i = 0; i < len; i++)
{
int k = i;
for (j = i + 1; j < len; j++)
{
if (a[j] < a[k]) k = j;
}
if (k != i)
{
int temp = a[i];
a[i] = a[k];
a[k] = temp;
}
}
dispArray(a, len);
}
int main()
{
int num[] = { 23,15,7,14,1,8,92,43,5,2,16,19,80,72,34 };
int len = sizeof(num) / sizeof(num[0]);
cout << "排序前:" << endl;
dispArray(num, len);
cout << "直接插入排序后:" << endl;
directInsertionSort(num, len);
cout << "希尔排序后:" << endl;
shellSort(num, len);
cout << "冒泡排序后:" << endl;
bubbleSort(num, len);
int *a = new int[len];
int i;
for (i = 0; i < len; i++)
a[i] = num[i];
cout << "快速排序后:" << endl;
quickSort(a, 0, len-1);
dispArray(a, len);
cout << "堆排序后:" << endl;
heapSort(num, len);
cout << "选择排序后:" << endl;
selectSort(num, len);
}
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" 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>15.0</VCProjectVersion>
<ProjectGuid>{E947DC8F-4FEC-4885-B082-EF09967AA4A2}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>排序</RootNamespace>
<WindowsTargetPlatformVersion>10.0.17763.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>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</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" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="pch.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="排序.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
\ No newline at end of file
<?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;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="头文件">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;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>
<ClInclude Include="pch.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="pch.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="排序.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
</Project>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册