施工阶段1:快速排序

This commit is contained in:
_Karasu_ 2022-08-09 23:44:49 +08:00
parent 5c65ce03be
commit f10bf55a2e
10 changed files with 206 additions and 0 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
bin/
obj/
/packages/
riderModule.iml
/_ReSharper.Caches/

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RiderProjectSettingsUpdater">
<option name="vcsConfiguration" value="2" />
</component>
</project>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -0,0 +1,116 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoGeneratedRunConfigurationManager">
<projectFile>Algorithm-FSharp/Algorithm-FSharp.fsproj</projectFile>
</component>
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="32b2067c-6667-4162-834b-afaa5fbc533d" name="Changes" comment="" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="Git.Settings">
<option name="PREVIOUS_COMMIT_AUTHORS">
<list>
<option value="lucas8485 &lt;1443937075@qq.com&gt;" />
<option value="1443937075@qq.com" />
<option value="lucas8485" />
<option value="Lucas8485" />
</list>
</option>
<option name="SET_USER_NAME_GLOBALLY" value="false" />
</component>
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
<component name="ProjectId" id="2D7ceCf2ipUh8vCgOpraTn1Gs0T" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;ASKED_SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;,
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;,
&quot;WebServerToolWindowFactoryState&quot;: &quot;false&quot;,
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;project.propDebugger&quot;,
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
}
}</component>
<component name="RunManager">
<configuration name="Algorithm-FSharp" type="DotNetProject" factoryName=".NET Project">
<option name="EXE_PATH" value="" />
<option name="PROGRAM_PARAMETERS" value="" />
<option name="WORKING_DIRECTORY" value="" />
<option name="PASS_PARENT_ENVS" value="1" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="PROJECT_PATH" value="$PROJECT_DIR$/Algorithm-FSharp/Algorithm-FSharp.fsproj" />
<option name="PROJECT_EXE_PATH_TRACKING" value="1" />
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="1" />
<option name="PROJECT_KIND" value="DotNetCore" />
<option name="PROJECT_TFM" value="" />
<method v="2">
<option name="Build" />
</method>
</configuration>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="32b2067c-6667-4162-834b-afaa5fbc533d" name="Changes" comment="" />
<created>1660053659032</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1660053659032</updated>
<workItem from="1660053666119" duration="717000" />
<workItem from="1660054562587" duration="1032000" />
<workItem from="1660055708455" duration="4008000" />
</task>
<task id="LOCAL-00001" summary="施工阶段1 快速排序">
<created>1660059459924</created>
<option name="number" value="00001" />
<option name="presentableId" value="LOCAL-00001" />
<option name="project" value="LOCAL" />
<updated>1660059459924</updated>
</task>
<option name="localTasksCounter" value="2" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
<component name="UnityCheckinConfiguration" checkUnsavedScenes="true" />
<component name="UnityUnitTestConfiguration" currentTestLauncher="NUnit" />
<component name="Vcs.Log.Tabs.Properties">
<option name="TAB_STATES">
<map>
<entry key="MAIN">
<value>
<State />
</value>
</entry>
</map>
</option>
</component>
<component name="VcsManagerConfiguration">
<option name="CLEAR_INITIAL_COMMIT_MESSAGE" value="true" />
<MESSAGE value="施工阶段1" />
<MESSAGE value="施工阶段1快速排序" />
<MESSAGE value="施工阶段1 快速排序" />
<option name="LAST_COMMIT_MESSAGE" value="施工阶段1 快速排序" />
</component>
</project>

16
Algorithm-FSharp.sln Normal file
View File

@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Algorithm-FSharp", "Algorithm-FSharp\Algorithm-FSharp.fsproj", "{BA0BCD71-D94F-4B20-85A9-4CED4FD6DE99}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BA0BCD71-D94F-4B20-85A9-4CED4FD6DE99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BA0BCD71-D94F-4B20-85A9-4CED4FD6DE99}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BA0BCD71-D94F-4B20-85A9-4CED4FD6DE99}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BA0BCD71-D94F-4B20-85A9-4CED4FD6DE99}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>Algorithm_FSharp</RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="QuickSort.fs" />
<Compile Include="Program.fs" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,8 @@
// For more information see https://aka.ms/fsharp-console-apps
module Algorithm_FSharp.Program
open Algorithm_FSharp.QuickSort
//
let myList = [1; 1; 4; 5; 1; 4; 1; 9; 1; 9; 8; 1; 0] //
printfn $"%A{myList
|> quicksort}"

View File

@ -0,0 +1,23 @@
module Algorithm_FSharp.QuickSort
//
// partition : ('a bool) -> 'a list -> 'a list * 'a list
// pred
let rec partition pred lst =
match lst with //
| [] -> [],[] // list
| head::tail -> // listheadtail
let matched, unmatched = partition pred tail // partitionmatchedunmatched
match (pred head) with //
| true -> head::matched, unmatched // matched
| false -> matched, head::unmatched // unmatched
// quicksort : 'T list -> 'T list
// F#
let rec quicksort i =
match i with //
| [] -> [] //
| [single] -> [single] //
| head :: tail -> //
let leftList, rightList = partition (fun item -> item <= head) tail // partition
quicksort(leftList) @ [head] @ quicksort(rightList) //