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

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" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <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="施工阶段3选择排序">
<change afterPath="$PROJECT_DIR$/Algorithm-FSharp/SelectionSort.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$/.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/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> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -97,7 +97,7 @@
<workItem from="1660181422024" duration="2137000" /> <workItem from="1660181422024" duration="2137000" />
<workItem from="1660186635954" duration="1867000" /> <workItem from="1660186635954" duration="1867000" />
<workItem from="1660231505344" duration="3491000" /> <workItem from="1660231505344" duration="3491000" />
<workItem from="1660267756436" duration="6060000" /> <workItem from="1660267756436" duration="6685000" />
</task> </task>
<task id="LOCAL-00001" summary="施工阶段1 快速排序"> <task id="LOCAL-00001" summary="施工阶段1 快速排序">
<created>1660059459924</created> <created>1660059459924</created>
@ -127,7 +127,14 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1660187524761</updated> <updated>1660187524761</updated>
</task> </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 /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
@ -153,6 +160,7 @@
<MESSAGE value="施工阶段1快速排序" /> <MESSAGE value="施工阶段1快速排序" />
<MESSAGE value="真的只是一点小问题!" /> <MESSAGE value="真的只是一点小问题!" />
<MESSAGE value="施工阶段2归并排序" /> <MESSAGE value="施工阶段2归并排序" />
<option name="LAST_COMMIT_MESSAGE" value="施工阶段2归并排序" /> <MESSAGE value="施工阶段3选择排序" />
<option name="LAST_COMMIT_MESSAGE" value="施工阶段3选择排序" />
</component> </component>
</project> </project>

View File

@ -1,26 +1,25 @@
module Algorithm_FSharp.MergeSort module Algorithm_FSharp.MergeSort
// //
// merge : 'a list -> 'a list -> 'a list -> 'a list // merge : 'a list -> 'a list -> 'a list
// lhsrhsres // lhsrhs
let rec merge lhs rhs res = let rec merge lhs rhs =
match (lhs, rhs) with // lhsrhs match (lhs, rhs) with // lhsrhs
| [], [] -> res // res | [], [] -> [] // res
| [], ys -> res @ ys // lhsrhsres | [], ys -> ys // lhsrhs
| xs, [] -> res @ xs // rhslhsres | xs, [] -> xs // rhslhs
| x::xs, y::ys -> // | x::xs, y::ys -> //
match x < y with // match x < y with //
| true -> merge xs (y::ys) (res @ [x]) // lhsrhsres | true -> x::(merge xs (y::ys)) // lhsrhsx
| false -> merge (x::xs) ys (res @ [y]) // rhslhsres | false -> y::(merge (x::xs) ys) // rhslhsy
// F# // F#
// mergesort : 'a list -> 'a list // mergesort : 'a list -> 'a list
let rec mergesort arr = let rec mergesort = function
match arr with // | [] -> [] //
| [] -> [] // arr
| [single] -> [single] | [single] -> [single]
| _ -> // arr | xs -> //
let mid = arr.Length / 2 // let mid = xs.Length / 2 //
let left, right = arr // let left, right = xs //
|> List.splitAt mid |> 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 // For more information see https://aka.ms/fsharp-console-apps
module Algorithm_FSharp.Program module Algorithm_FSharp.Program
open Algorithm_FSharp.SelectionSort open Algorithm_FSharp.QuickSort
open Algorithm_FSharp.TestList open Algorithm_FSharp.TestList
// //
printfn $"%A{myList 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 // partition : ('a -> bool) -> 'a list -> 'a list * 'a list
// pred // pred
let rec partition pred lst = let rec partition pred = function
match lst with // | [] -> [],[] //
| [] -> [],[] // list | head::tail -> // headtail
| head::tail -> // listheadtail
let matched, unmatched = partition pred tail // partitionmatchedunmatched let matched, unmatched = partition pred tail // partitionmatchedunmatched
match (pred head) with // match (pred head) with //
| true -> head::matched, unmatched // matched | true -> head::matched, unmatched // matched
@ -14,8 +13,7 @@ let rec partition pred lst =
// quicksort : 'a list -> 'a list // quicksort : 'a list -> 'a list
// F# // F#
let rec quicksort i = let rec quicksort = function
match i with //
| [] -> [] // | [] -> [] //
| [single] -> [single] // | [single] -> [single] //
| head :: tail -> // | head :: tail -> //