小编Tie*_*Two的帖子

如何在 Map 中找到最小元素并返回一个元组(键,最小元素)?

我有这些类型:

type position = float * float
type node = position
Run Code Online (Sandbox Code Playgroud)

我已经编写了这些模块来创建我的 Map :

module MyMap =
  struct
  type t = node
  let compare (a1,b1) (a2,b2) =
    if a1 > a2 then 1
     else if a1 < a2 then -1
     else if b1 > b2 then 1
       else if b1 < b2 then -1

       else 0
  end

module DistMap = Map.Make(MyMap)
Run Code Online (Sandbox Code Playgroud)

我曾尝试编写使用过的函数,iter但尝试以正确的语法表达我的想法没有成功。

我的目标是能够有一个函数,它将 Map 作为参数并返回一个包含最小元素及其键的元组。

谢谢。

ocaml dictionary minimum

0
推荐指数
1
解决办法
75
查看次数

标签 统计

dictionary ×1

minimum ×1

ocaml ×1