graph - 从 Clojure 中表示为向量的树中获取边

标签 graph clojure tree edges

我有一棵这样的树:

[:root
  [:a [:b [:c [:g]]]]
  [:d [:e [:f [:g]]]]]

我怎样才能得到边缘,即:

[[:root :a] [:root :d] [:a :b] [:b :c] [:c :g] [:d :e] [:e :f] [:f :g]]

最佳答案

这是我在检查您的答案之前得出的结论。除非我遗漏了什么,否则似乎更符合习惯。

(defn vec->edges [v-tree]
  (->> v-tree
       (tree-seq vector? next)
       (mapcat (fn [[a & children]]
                 (map (fn [[b]] [a b]) children)))))

关于graph - 从 Clojure 中表示为向量的树中获取边,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63679058/

相关文章:

javascript - 如何在 d3.js 中更新图表图例?

java - 使用 csv 中的数据在 html 中创建图形

Clojurescript 核心异步 : Async condition inside go

data-structures - 一棵二叉树在 n 级可以有多少个节点?用归纳法证明答案

javascript - vis.js 3D条形图: Set bar color based on z-coordinate value

java - 如果只给出事件点,如何绘制图表?

java - 在 Java/Clojure 中生成包含使用 OpenType 功能的文本的图像

tomcat - IntelliJ + Maven + Tomcat 中的 Clojure Webapp

c++ - 从具有私有(private)内部类 C++ 的类继承

data-structures - 红黑树和AVL树的区别