⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 list.java

📁 和YACC一样
💻 JAVA
字号:
/*File:	 List.javaAuthor:  zerksis d. umrigar (zdu@acm.org)Copyright (C) 1997 Zerksis D. UmrigarLast Update Time-stamp: "97/07/26 17:05:59 zdu"This code is distributed under the terms of the GNU General Public License.See the file COPYING with this distribution, or		http://www.fsf.org/copyleft/gpl.htmlTHERE IS ABSOLUTELY NO WARRANTY FOR THIS PROGRAM.*/package zdu.zydebug;import java.util.Enumeration;import java.util.NoSuchElementException;public class List implements XEnumeration {  public List() {    obj= null; tail= null;  }  /** Adds the specified object obj to the list.   * @param	obj - the component to be added.   */  public void addElement(Object  obj) {    List newList= new List();    newList.obj= obj; newList.tail= tail;    tail= newList;  }  /** Returns true iff the list contains Object obj (using equals). */  public boolean contains(Object  obj) {    for (List p= tail; p != null; p= p.tail) {      if (obj.equals(p.obj)) return true;    }    return false;  }  public Object elementAt(int  index) {    int i= 0;    for (List p= tail; p != null; p= p.tail) {      if (i == index) return p.obj;      i++;    }    throw new NoSuchElementException("List.elementAt()");  }  public XEnumeration elements() {    List list= new List();    list.tail= tail;    return list;  }    public Object firstElement() {    if (tail != null) {       return tail.obj;    }    else {      throw new NoSuchElementException("List.firstElement()");    }  }  public List restElements() {    if (tail != null) {       return tail;    }    else {      throw new NoSuchElementException("List.firstElement()");    }  }      public boolean isEmpty() {    return tail == null;  }  public int size() {    int i= 0;    for (List p= tail; p != null; p= p.tail) i++;    return i;  }  public String toString() {    int n= 5;    int i= 0;    StringBuffer b= new StringBuffer();    List p;    for (p= tail; p != null && i < n; p= p.tail, i++) {      b.append(p.obj.toString() + " ");    }    if (p != null) b.append("...");    return super.toString() + "(" + size() + ")" + "[" + b.toString() + "]";  }  public boolean hasMoreElements() {    return tail != null;  }  public Object getXEnumerationElement() {    if (tail != null) return tail.obj;    else throw new NoSuchElementException("List.getXEnumerationElement()");  }  public void stepXEnumeration() {    if (tail != null) tail= tail.tail;    else throw new NoSuchElementException("List.getXEnumerationElement()");  }  public Object nextElement() {    Object obj= getXEnumerationElement();    stepXEnumeration();    return obj;  }  private Object obj;  private List tail;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -