package sktask;
import java.util.ArrayList;
import java.util.List;
class Tree {
private String key;
private String value;
private List<Tree> children;
public Tree(){};
public Tree(String key,String value){this.key=key;this.value=value;}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public List<Tree> getChildren() {
return children;
}
public void setChildren(List<Tree> children) {
this.children = children;
}
}
public class DoubleTree{
public static void insert(Tree parents,Tree data){
List<Tree> children=parents.getChildren();
if(children==null) children=new ArrayList<Tree>();
children.add(data);
parents.setChildren(children);
}
public static void get(Tree parents){
String key=parents.getKey();
String value=parents.getValue();
System.out.println(key+"=========="+value);
List<Tree> children=parents.getChildren();
if(null!=children && children.size()>0)
for(Tree t:children)
get(t);
}
public static void main(String[] args){
Tree root=new Tree();
root.setKey("root");
root.setValue("root");
Tree child1=new Tree("child1","child1");
Tree child2=new Tree("child2","child2");
Tree child3=new Tree("child3","child3");
Tree child4=new Tree("child4","child4");
Tree next1=new Tree("next1","next1");
Tree next2=new Tree("next2","next2");
Tree next3=new Tree("next3","next3");
Tree next4=new Tree("next4","next4");
Tree next5=new Tree("next5","next5");
insert(root, child1);
insert(root, child2);
insert(root, child3);
insert(root, child4);
insert(child1, next1);
insert(child1, next2);
insert(child1, next3);
insert(child2, next2);
insert(child3, next3);
insert(child4, next4);
get(root);
//get(child1);
}
}
import java.util.ArrayList;
import java.util.List;
class Tree {
private String key;
private String value;
private List<Tree> children;
public Tree(){};
public Tree(String key,String value){this.key=key;this.value=value;}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public List<Tree> getChildren() {
return children;
}
public void setChildren(List<Tree> children) {
this.children = children;
}
}
public class DoubleTree{
public static void insert(Tree parents,Tree data){
List<Tree> children=parents.getChildren();
if(children==null) children=new ArrayList<Tree>();
children.add(data);
parents.setChildren(children);
}
public static void get(Tree parents){
String key=parents.getKey();
String value=parents.getValue();
System.out.println(key+"=========="+value);
List<Tree> children=parents.getChildren();
if(null!=children && children.size()>0)
for(Tree t:children)
get(t);
}
public static void main(String[] args){
Tree root=new Tree();
root.setKey("root");
root.setValue("root");
Tree child1=new Tree("child1","child1");
Tree child2=new Tree("child2","child2");
Tree child3=new Tree("child3","child3");
Tree child4=new Tree("child4","child4");
Tree next1=new Tree("next1","next1");
Tree next2=new Tree("next2","next2");
Tree next3=new Tree("next3","next3");
Tree next4=new Tree("next4","next4");
Tree next5=new Tree("next5","next5");
insert(root, child1);
insert(root, child2);
insert(root, child3);
insert(root, child4);
insert(child1, next1);
insert(child1, next2);
insert(child1, next3);
insert(child2, next2);
insert(child3, next3);
insert(child4, next4);
get(root);
//get(child1);
}
}