- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
首先,我看到了this问题,但这并不能解决我的问题。
我有一个数据结构(Trie),其中包含树的每个节点的字符。
字符可以在不同的节点中重复,因此字符不是节点的ID。
如果插入{aa, abc, cash, cicero, cicelies, cigar}
,我的树将类似于:
我的课程:
class TrieNode {
public char content;
public boolean isEnd;
public int count;
public LinkedList<TrieNode> childList;
public TrieNode(char c) {
childList = new LinkedList<TrieNode>();
isEnd = false;
content = c;
count = 0;
}
public TrieNode subNode(char c) {
if(childList != null)
for(TrieNode eachChild : childList)
if(eachChild.content == c)
return eachChild;
return null;
}
}
class Trie {
private TrieNode root;
public Trie() {
root = new TrieNode('*');
}
public void insert(String word) {
if(search(word) == true)
return;
TrieNode current = root;
for(char ch : word.toCharArray()) {
TrieNode child = current.subNode(ch);
if(child != null)
current = child;
else {
current.childList.add(new TrieNode(ch));
current = current.subNode(ch);
}
current.count++;
}
current.isEnd = true;
}
public void print() {
String fileDot = "./outputFile";
try {
FileWriter f = new FileWriter(fileDot);
BufferedWriter bf = new BufferedWriter(f);
out = new PrintWriter(bf);
createDotString();
out.close();
File g = new File(fileDot);
String arg1 = g.getAbsolutePath();
String arg2 = arg1 + ".png";
String[] c = {"dot", "-Tpng", arg1, "-o", arg2};
Process p = Runtime.getRuntime().exec(c);
p.waitFor();
}
catch(IOException ioe) {
System.out.println(ioe);
}
catch(InterruptedException iee) {
System.out.println(iee);
}
}
public void createDotString() throws IOException {
out.println("graph T {\n\trankdir = TB;");
printNodeDot(root);
out.println("}");
}
private void printNodeDot(TrieNode node) {
for(TrieNode child : node.childList) {
out.println("\t\"" + node.content + "\" -- \"" + child.content + "\";");
printNodeDot(child);
}
}
}
graph T {
rankdir = TB;
"*" -- "a";
"a" -- "a";
"a" -- "b";
"b" -- "c";
"*" -- "c";
"c" -- "a";
"a" -- "s";
"s" -- "h";
"c" -- "i";
"i" -- "c";
"c" -- "e";
"e" -- "r";
"r" -- "o";
"e" -- "l";
"l" -- "i";
"i" -- "e";
"e" -- "s";
"i" -- "g";
"g" -- "a";
"a" -- "r";
}
最佳答案
您为每个节点添加一个ID是正确的-我只是将每个节点的完整路径用作其ID。对于graphviz,我还要拆分节点的定义(ID和相应的标签)和边列表(ID到ID)。
结果可能是这样的:
graph T {
// nodes
"*" [label="*"];
"*a" [label="a"];
"*aa" [label="a"];
"*ab" [label="b"];
"*abc" [label="c"];
"*c" [label="c"];
...
// edges
"*" -- "*a";
"*a" -- "*aa";
"*a" -- "*ab";
"*ab" -- "*abc";
"*" -- "*c";
"*c" -- "*ca";
"*ca" -- "*cas";
"*cas" -- "*cash";
...
}
var lst = new[]{"aa", "abc", "cash", "cicero", "cicelies", "cigar"};
var nodes = lst.Select(s => "*" + s).ToList()
.SelectMany(w => Enumerable.Range(1, w.Length).Select (i => w.Substring(0, i)))
.Distinct()
.ToList();
var nodedefs = nodes.Select(n => string.Format("\"{0}\" [label=\"{1}\"];", n, n.Last()));
var edges = nodes.Where(n => n.Length > 1)
.Select(n => String.Format("\"{0}\" -- \"{1}\";", n.Substring(0, n.Length-1), n));
var graph = string.Join(Environment.NewLine, nodedefs.Concat(edges));
关于java - 将一些节点放在Dot中的同一级别上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35875072/
我正在使用 XCode 中的 SwiftUI 为 iPhone 编写应用程序。 在其中一个 View 中,有一个 Text 标签,每当按下按钮时都会更改其文本。 整个 View 是 Spring 动画
我有一个功能可以在生成报告时在弹出窗口中显示点点点。我想显示文本: 正在生成报告。生成报告..正在生成报告... ...重复,直到报告准备好。到目前为止,我只能在弹出窗口中获取三个点,而无法获取其他文
是否可以从 ... 中删除元素并将 ... 传递给其他函数?我的前两次尝试失败了: parent = function(...) { a = list(...) str(a) a$t
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
http://pastebin.com/index/9M2rA8cx那有我所有的代码。 您会注意到这两个 div 在 large.css 中居中。但是,文本在每个“。”之后重新居中。被申请;被应用。如
特殊文件 . 和 .. 是否实际存在并作为普通文件存储/位于文件系统中,或者它们是否仅在访问时解释/创建文件系统处理程序? .(当前目录) ..(父目录) 我的假设是它们不存在——否则,当您创建符号链
我想用...指示我想从 data.table 的自定义函数返回的变量目的。这是一个最小的可复制示例: library(data.table) d = data.table(mtcars) getvar
我想允许用户输入以下十进制或整数值 (A) .5 0.500 3 0 0.0 30 500000 4000.22 0. 这是我使用的以下正则表达式: factor: /^-?\d*[.]??\d*$/
我似乎明白 TLD 后的点无关紧要,例如: http://example.com/somepage/ == http://example.com./somepage/ (注意 TLD 后面的点) 我的
我试图用这个 DOT 输入文件创建一个简单的循环图: digraph { rankdir=LR; node0 [label = "0", group="bottom"]; n
我的问题与 this one 基本相同但给出的答案对我不起作用。 这是一个示例渲染 (source)和 compound=true; overlap=scalexy; splines=true; la
我正在尝试为作业问题制作一个点脚本生成器,它进行得很顺利,但我遇到了这个问题,其中一些未在子图中定义的节点被放置在其中。例如以下点脚本: digraph dg { compound=true;
我写了下面的 DOT 来生成图表。除了定义和布置的节点外,我想在标记为 L 的边缘的左侧和右侧放置一个节点,它们应该靠近 L,并且在 NODE3 和 NODE6 之间。 我尝试了一些不可见的节点。新节
我正在使用 python 和 matplotlib 来生成图形输出。 有没有一种简单的方法来生成点划线样式? 我知道 '--'、'-.' 和 ':' 选项。不幸的是,'-..' 不会产生点划线。 我查
给定以下字符串: "foo.bar.baz" 使用 Java String split 可以很容易地在“点”上分割它: split("foo.bar.baz", "\.") 但是,如果我想保留该点(如
有区别吗 import numpy as np np.dot(a,b) 和 a.dot(b) 内部?我找不到关于后一种方法的任何文档。 最佳答案 如果a 是一个数组,它们是等价的。您找不到关于 dot
有区别吗?如果不是,按惯例首选什么?性能似乎几乎相同。 a=np.random.rand(1000,1000) b=np.random.rand(1000,1000) %timeit a.dot(b)
如何使用 gvpr 将 DOT 语言中包含多个图形的文件拆分为多个 DOT 文件? 输入(1 个文件): # single.dot digraph one { a -> b; } digraph
RecursiveDirectoryIterator 似乎从本地主机和实时服务器给我两个不同的结果, define ('WEBSITE_DOCROOT', str_replace('\\', '/',
我有这样的例子: "hello . world . thanks ." 我想得到这个: "hello. world. thanks." 我试过了 text = text.replaceAll(" ."
我是一名优秀的程序员,十分优秀!