当前位置: 首页 >> 程序设计 >> Java >> Java的通用树源代码
 

Java的通用树源代码

作者:      来源:zz     发表时间:2007-02-05     浏览次数:      字号:    

import java.util.ArrayList;

public class Node {
 public Node parent = null;

 public ArrayList childrenList = new ArrayList();

 public String value;

 boolean isRoot = false;

 public Node() {

 }

 public Node(String value) {
  this.value = value;
 }

 public void addChild(Node child) {
  childrenList.add(child);
 }

 public Node getChild(int index) {
  return childrenList.get(index);
 }

 public int getChildCount() {
  return childrenList.size();
 }

 public int getDepth() {
  if (isRoot())
   return 0;
  else
   return 1 + getParent().getDepth();
 }

 public boolean isInternalNode() {
  if (childrenList != null)
   return true;
  else
   return false;
 }

 public boolean isLeaf() {
  if (childrenList == null)
   return true;
  else
   return false;
 }

 public boolean isRoot() {
  return isRoot;
 }

 public void removeChildAt(int index) {
  childrenList.remove(index);
 }

 public void setRoot() {
  isRoot = true;
 }

 public Node getParent() {
  return parent;
 }

 public void setParent(Node parent) {
  this.parent = parent;
 }

 public ArrayList getChildrenList() {
  return childrenList;
 }
}

责任编辑 webmaster

 
 
 
 
 
评论更多>>
 
 
 
发表
 
姓名: QQ:
性别: MSN:
E-mail: 主页:
评分: 1 2 3 4 5
评论内容:
验证码:
  
  • 请遵守《互联网电子公告服务管理规定》及中华人民共和国其他各项有关法律法规。
  • 严禁发表危害国家安全、损害国家利益、破坏民族团结、破坏国家宗教政策、破坏社会稳定、侮辱、诽谤、教唆、淫秽等内容的评论 。
  • 用户需对自己在使用本站服务过程中的行为承担法律责任(直接或间接导致的)。
  • 本站管理员有权保留或删除评论内容。
  • 评论内容只代表网友个人观点,与本网站立场无关。
  •