我在 F# 中制作了一个看起来像队列的数据结构,我不确定是否可以将其称为“队列”,因为它可以在序列中间随机访问并对其进行编辑。
type item =
{
name : string
mutable point : int
}
type Queue = class
val mutable q : item []
new () = { q = Array.empty; }
member this.enq i =
let mutable b = true
try
this.q <- Array.append this.q [|i|]
with
| _ as e -> (b <- false)
b
member this.deq (i : byref<item>) =
let mutable b = true
try
i <- this.q.[0]
this.q <- Array.sub this.q 1 (this.q.Length - …Run Code Online (Sandbox Code Playgroud)