生成唯一的密钥

生成唯一的密钥

问题描述:

我有一个类似的问题了一只计算器文章中解决(Creating a java hierarchial treeset from a flat list生成唯一的密钥

什么我目前正在试图做的是打印树到一个文件中,有以下几点:

  • 父母需要先打印出来,所以如果他们被导入(某处),他们首先被创建,这样子女就可以被创建在他们的下面。
  • 我需要例如基于层次生成一个唯一的密钥:

    根>父>儿童> GrandChild1

    根>父>儿童> GrandChild2

>是节点的分隔符,但不介意这是什么...

有人能够建议一种方法,我可以生成唯一的密钥?

我不确定你的键是什么等,但它听起来微不足道。

使用root第一次使用前缀打印

这里是你如何打印打印前缀树(此树有数字,但它不应该的问题,你的想法)。下面的方法使用递归。

private void printPrefix(Node<?> node){ 

     //If node is null, reached end of chain, return to caller 
     if (node==null) { 
      return; 
     } 

     //Print self 
     System.out.print(node.getValue()); 
     System.out.print(" "); 

     //Print all children 
     for (Source child : node.children) //changed for multiple 
{ 
    printPrefix(child); 
} 

     return; 
    } 

关于更好的数据结构建议,你应该考虑一个b-tree。 https://www.google.com/search?q=b+tree&ie=UTF-8&oe=UTF-8&hl=en&client=safari#itp=open0

+0

感谢您的回复。我的结构没有左右节点,所以我如何使用上面的? – user2304232 2013-04-22 09:53:03

+0

更改为解决多个孩子 – 2013-04-22 12:09:35