修正冗余语法,对应修改了相关注释

This commit is contained in:
_Karasu_ 2022-08-12 12:36:53 +08:00
parent 1592f00810
commit c1533114d4
4 changed files with 34 additions and 29 deletions

View File

@ -7,11 +7,11 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="32b2067c-6667-4162-834b-afaa5fbc533d" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/Algorithm-FSharp/SelectionSort.fs" afterDir="false" />
<list default="true" id="32b2067c-6667-4162-834b-afaa5fbc533d" name="Changes" comment="施工阶段3选择排序">
<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/MergeSort.fs" beforeDir="false" afterPath="$PROJECT_DIR$/Algorithm-FSharp/MergeSort.fs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Algorithm-FSharp/Program.fs" beforeDir="false" afterPath="$PROJECT_DIR$/Algorithm-FSharp/Program.fs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Algorithm-FSharp/QuickSort.fs" beforeDir="false" afterPath="$PROJECT_DIR$/Algorithm-FSharp/QuickSort.fs" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -97,7 +97,7 @@
<workItem from="1660181422024" duration="2137000" />
<workItem from="1660186635954" duration="1867000" />
<workItem from="1660231505344" duration="3491000" />
<workItem from="1660267756436" duration="6060000" />
<workItem from="1660267756436" duration="6685000" />
</task>
<task id="LOCAL-00001" summary="施工阶段1 快速排序">
<created>1660059459924</created>
@ -127,7 +127,14 @@
<option name="project" value="LOCAL" />
<updated>1660187524761</updated>
</task>
<option name="localTasksCounter" value="5" />
<task id="LOCAL-00005" summary="施工阶段3选择排序">
<created>1660278379103</created>
<option name="number" value="00005" />
<option name="presentableId" value="LOCAL-00005" />
<option name="project" value="LOCAL" />
<updated>1660278379103</updated>
</task>
<option name="localTasksCounter" value="6" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
@ -153,6 +160,7 @@
<MESSAGE value="施工阶段1快速排序" />
<MESSAGE value="真的只是一点小问题!" />
<MESSAGE value="施工阶段2归并排序" />
<option name="LAST_COMMIT_MESSAGE" value="施工阶段2归并排序" />
<MESSAGE value="施工阶段3选择排序" />
<option name="LAST_COMMIT_MESSAGE" value="施工阶段3选择排序" />
</component>
</project>

View File

@ -1,26 +1,25 @@
module Algorithm_FSharp.MergeSort
//
// merge : 'a list -> 'a list -> 'a list -> 'a list
// lhsrhsres
let rec merge lhs rhs res =
// merge : 'a list -> 'a list -> 'a list
// lhsrhs
let rec merge lhs rhs =
match (lhs, rhs) with // lhsrhs
| [], [] -> res // res
| [], ys -> res @ ys // lhsrhsres
| xs, [] -> res @ xs // rhslhsres
| [], [] -> [] // res
| [], ys -> ys // lhsrhs
| xs, [] -> xs // rhslhs
| x::xs, y::ys -> //
match x < y with //
| true -> merge xs (y::ys) (res @ [x]) // lhsrhsres
| false -> merge (x::xs) ys (res @ [y]) // rhslhsres
| true -> x::(merge xs (y::ys)) // lhsrhsx
| false -> y::(merge (x::xs) ys) // rhslhsy
// F#
// mergesort : 'a list -> 'a list
let rec mergesort arr =
match arr with //
| [] -> [] // arr
let rec mergesort = function
| [] -> [] //
| [single] -> [single]
| _ -> // arr
let mid = arr.Length / 2 //
let left, right = arr //
| xs -> //
let mid = xs.Length / 2 //
let left, right = xs //
|> List.splitAt mid
merge (mergesort left) (mergesort right) [] //
merge (mergesort left) (mergesort right) //

View File

@ -1,8 +1,8 @@
// For more information see https://aka.ms/fsharp-console-apps
module Algorithm_FSharp.Program
open Algorithm_FSharp.SelectionSort
open Algorithm_FSharp.QuickSort
open Algorithm_FSharp.TestList
//
printfn $"%A{myList
|> selection_sort}"
|> quicksort}"

View File

@ -3,10 +3,9 @@ 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 rec partition pred = function
| [] -> [],[] //
| head::tail -> // headtail
let matched, unmatched = partition pred tail // partitionmatchedunmatched
match (pred head) with //
| true -> head::matched, unmatched // matched
@ -14,8 +13,7 @@ let rec partition pred lst =
// quicksort : 'a list -> 'a list
// F#
let rec quicksort i =
match i with //
let rec quicksort = function
| [] -> [] //
| [single] -> [single] //
| head :: tail -> //