几种常见的数据结构的JAVA实现
ITree
package utility.structure.def;
/**
*
* @author odie.tang
*
* @version 1.0 10/30/09
*/
public interface ITree<E>{
E getData();
E remove();
void setData(E e);
int getDepth();
int getLevel();
ITree<E> getRoot();
ITree<E> getParent();
ITree<E> getFirstChild();
ITree<E> addFirtChild(E e);
ITree<E> getLastChild();
ITree<E> addLastChild(E e);
ITree<E> getNode(E e);
boolean isLeaf();
boolean isRoot();
boolean remove(E e);
}
IBinaryTree
package utility.structure.def;
public interface IBinaryTree<E> extends ITree<E>{
boolean hasLeftChild();
boolean isLeftChild();
IBinaryTree<E> getLeftChild();
IBinaryTree<E> addLeftChild(E e);
boolean hasRightChild();
boolean isRightChild();
IBinaryTree<E> getRightChild();
IBinaryTree<E> addRightChild(E e);
}
BinaryTree
package utility.structure;
import java.io.Serializable;
import java.util.ConcurrentModificationException;
import utility.structure.def.IBinaryTree;
import utility.structure.def.ITree;
/**
*
* @author odie.tang
*
* @since 1.0 11/01/09
*/
public class BinaryTree<E> implements IBinaryTree<E>,Serializable{
private static final long serialVersionUID = 1565285530988892541L;
private E data;
private BinaryTree<E> parent = null;
private BinaryTree<E> leftChild = null;
private BinaryTree<E> rightChild = null;
private int level;
private enum Child{left,right}
public BinaryTree(E root) {
this.data = root;
this.level = 1;
}
public BinaryTree(E root, E leftChild){
this.data = root;
this.level = 1;
new BinaryTree<E>(this,Child.left,leftChild);
}
public BinaryTree(E root, E leftChild,E rightChild){
this.data = root;
this.level = 1;
new BinaryTree<E>(this,Child.left,leftChild);
new BinaryTre
相关文档:
我们经常要将数字进行格式化,比如取2位小数,这是最常见的。Java 提供 DecimalFormat 类,帮你用最快的速度将数字格式化为你需要的样子。下面是一个例子:
importjava.text.DecimalFormat;
publicclassTestNumberFormat{
publicstaticvoidmain(String[]args){ ......
计算一下时间!我开始学习JAVA编程已经两个月了,每节课都是在学习一下理论的东西。感觉上没啥用处一样,所以自己着手做一些简单的JAVA编程。第一次编程肯定没法跟大师们比较了,但是这也见证了我努力的结果!
import java.awt.*;
import java.awt.event.*;
import java.util.Date;
import javax.swing.JPassword ......
我的java学习了一年有余,起初是胡乱学,后来觉得java非常有意思,并且想在这方面深入学习,现在才是Java学习真正的开始。我正在阅读corejava和编程思想,学完这三本后想搞j2ee的开发。本人对数据库也感兴趣,现在热衷于SQL,但是我相信自己最终会瞄准ORECAL(很大程度出于好奇心),其实现在觉得Java DB ......
把树形的结构抽象了一下。
ITree
package utility.structure.def;
/**
*
* @author odie.tang
*
* @version 1.0 10/30/09
*/
public interface ITree<E>{
E getData();
E remove();
void setData(E e);
int getDepth();
int getLevel();
ITree<E> getRoot();
......