在java的类库中java.util.*有各种容器。其中包括楼主所说的。

解决方案 »

  1.   

    当然也可以自己写
    这是别人写的二叉树,我转贴一下
    /**  Component.java    **************/
    package binarytree;
    public abstract class   Component {
    private String name;
    public abstract Component addChild(Component leftChild,Component rightChild);
    public String getName(){return name;}
        public void getTreeInfo(){}
         public abstract int  getLength();
    }/**  Leaf.java    **************/
    package binarytree;
    public class Leaf extends Component{
     private String name;
     private Component leaf=null;
     public Leaf(String name) {
     this.name=name;
     }
      public Component addChild(Component leftChild,Component rightChild){
           return this;
        }
         public String getName(){
         return name;
        }
          public int  getLength() {
        return 1;
      }
     public static void main(String[] args) {
     }
    }/**  Tree.java    **************/
    package binarytree;
    public class Tree extends Component {
     private String name;
     private Component leftChild;
     private Component rightChild;
     public Tree(String name,Component leftChild,Component rightChild) {
     this.name=name;
     this.leftChild=leftChild;
     this.rightChild=rightChild;
     }
     public Tree(String name) {
     this.name=name;
     this.leftChild=null;
     this.rightChild=null;
     }
       public Component addChild(Component leftChild,Component rightChild){
       this.leftChild=leftChild;
       this.rightChild=rightChild;
       return this;
       }
       public String getName(){
       return name;
       }
       public void getTreeInfo()    
        //得到树或叶子的详细信息
      //先打印自己的名字,再遍例左孩子,再遍例右孩子
      //如果左孩子或右孩子是树,递归调用
      {
       System.out.println(" this tree's name is "+getName());
       if(this.leftChild instanceof Leaf)
       {
       System.out.println(getName()+"'s left child is "+this.leftChild.getName()+",it is a Leaf");
       }
       if(this.leftChild instanceof Tree){
       System.out.println(getName()+"'s left child is "+this.leftChild.getName()+",it is a Tree");
       this.leftChild.getTreeInfo();
       }
       if(this.leftChild==null)
       {
       System.out.println(getName()+"'s left child is a null");
       }
       if(this.rightChild instanceof Leaf)
       {
       System.out.println(getName()+"'s right child is "+this.rightChild.getName()+",it is a Leaf");
       }
       if(this.rightChild instanceof Tree) {
       System.out.println(getName()+"'s right child is "+this.rightChild.getName()+",it is a Tree");
       this.rightChild.getTreeInfo();
       }
       if(this.rightChild==null)
       {
       System.out.println(getName()+"'s right child is a null");
       }
       //System.out.println(getName()+"'s 高度 是 "+getLength());
       }
      public int  getLength() {
     //比较左孩子或右孩子的高度,谁大,+1 返回
     // 空孩子的处理
      if(this.leftChild==null) {
          if(this.rightChild==null)
          return 1;
          else
               return this.rightChild.getLength()+1;
         }
      else {
             if(this.rightChild==null) {
              return this.leftChild.getLength()+1;
                   }
             else {
                  if((this.leftChild.getLength())>=(this.rightChild.getLength()))
                  return this.leftChild.getLength()+1;
                  else
                  return this.rightChild.getLength()+1;
                  }
           }
      }
    }
      

  2.   

    给你写一个简单的"栈"数据结构的例子吧
    class Stack
    {
      private class Node
      {
        public Object data;
        public Node next;
        public Node(Object data,Node next){this.data = data; this.next = next;}
      }  private Node head = null;  public boid push(Object data)
      {
        Node n = new Node(data,head);
        head = n; 
      }
      public Object pop()
      {
        if(head != null){
          Node n = head;
          head = head.next;
          return n.data;
        }else{
          throw RuntimeException("No such element!"); 
        }     
      }
      public boolean empty()
      {
        return head==null;
      }
    }
      

  3.   

    java的对象都是引用,这本身就是一种指针,但比指针安全.
      

  4.   

    关于   java的对象都是引用   我在看外文教材时理解到了!可是咱们自己的教材却要么只字不提,要么坚决否认存在指针。
      

  5.   

    即使是外文教材,也从来没有说java里有指针。只是说对象的引用可以当做指针来理解。
      

  6.   

    qqbz(qqbz) 大哥没有看清楚我说什么吧?
      

  7.   

    即使是外文教材,也从来没有说java里有指针?不会吧,java.lang.NullPointerException该当何解?
      

  8.   

    不要把C++中的引用和Java中的引用混淆,这两者的定义差得很远!!!Java中的引用其实可以叫一种"约束"指针
    一个类指针只能指向  它的类  的对象,或者  它的子类  的对象,或者null   一个接口指针只能指向 实现它的类 的对象, 或者null