施工阶段4:插入排序

This commit is contained in:
_Karasu_ 2022-08-14 19:24:20 +08:00
parent 50961ca46e
commit dbd410feb8
5 changed files with 42 additions and 3 deletions

View File

@ -7,10 +7,11 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="32b2067c-6667-4162-834b-afaa5fbc533d" name="Changes" comment="">
<list default="true" id="32b2067c-6667-4162-834b-afaa5fbc533d" name="Changes" comment="施工阶段4插入排序">
<change afterPath="$PROJECT_DIR$/Algorithm-FSharp/IntersectionSort.fs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/.idea.Algorithm-FSharp/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.Algorithm-FSharp/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Algorithm-FSharp/Algorithm-FSharp.fsproj" beforeDir="false" afterPath="$PROJECT_DIR$/Algorithm-FSharp/Algorithm-FSharp.fsproj" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Algorithm-FSharp/TestList.fs" beforeDir="false" afterPath="$PROJECT_DIR$/Algorithm-FSharp/TestList.fs" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -98,6 +99,7 @@
<workItem from="1660231505344" duration="3491000" />
<workItem from="1660267756436" duration="7666000" />
<workItem from="1660313412199" duration="3066000" />
<workItem from="1660475772512" duration="451000" />
</task>
<task id="LOCAL-00001" summary="施工阶段1 快速排序">
<created>1660059459924</created>
@ -141,7 +143,14 @@
<option name="project" value="LOCAL" />
<updated>1660279013996</updated>
</task>
<option name="localTasksCounter" value="7" />
<task id="LOCAL-00007" summary="施工阶段4插入排序">
<created>1660475901956</created>
<option name="number" value="00007" />
<option name="presentableId" value="LOCAL-00007" />
<option name="project" value="LOCAL" />
<updated>1660475901956</updated>
</task>
<option name="localTasksCounter" value="8" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
@ -169,6 +178,7 @@
<MESSAGE value="施工阶段2归并排序" />
<MESSAGE value="施工阶段3选择排序" />
<MESSAGE value="修正冗余语法,对应修改了相关注释" />
<option name="LAST_COMMIT_MESSAGE" value="修正冗余语法,对应修改了相关注释" />
<MESSAGE value="施工阶段4插入排序" />
<option name="LAST_COMMIT_MESSAGE" value="施工阶段4插入排序" />
</component>
</project>

View File

@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/PencilsConfiguration/ActualSeverity/@EntryValue">INFO</s:String></wpf:ResourceDictionary>

View File

@ -8,6 +8,7 @@
<ItemGroup>
<Compile Include="TestList.fs" />
<Compile Include="IntersectionSort.fs" />
<Compile Include="SelectionSort.fs" />
<Compile Include="MergeSort.fs" />
<Compile Include="QuickSort.fs" />

View File

@ -0,0 +1,23 @@
module Algorithm_FSharp.IntersectionSort
//
// intersect : 'a -> 'a list -> 'a list
let rec intersect elem = function
| [] -> [elem] //
| x::xs -> //
match x < elem with // x
| true -> // x
match xs with // xs
| [] -> [elem; x] // xselem
| y::ys -> // xsxsyys
match elem < y with // elemy
| true -> [x; elem; y] @ ys // 若x < elem < yxy
| false -> x::(xs |> intersect elem) // 若elem > y
| false -> elem::x::xs //
// F#
// intersection_sort : 'a list -> 'a list
let rec intersection_sort = function
| [] -> [] //
| [single] -> [single]
| x::xs -> xs //
|> intersection_sort //
|> intersect x //

View File

@ -37,6 +37,9 @@ let myList = [
512
652
111
233
233
233
851
98
277