Java语言-Test1.java

    技术2025-08-14  13

    import javax.xml.soap.Node; interface Collection{ public void add(Object x); public Iterator iterator(); } interface Iterator{ public Object next(); public boolean hasNext(); } @SuppressWarnings("serial") class NoSuchElementException extends RuntimeException{} class LinkedList implements Collection{ Object elt; Node next=null; Node(Object elt){ this.elt=elt; } protected Node head=null,tail=null; public LinkedList() {} public void add(Object alt) { if(head==null) { head=new Node(elt); tail=head; } else { tail.next=new Node(elt); tail=tail.next; } } public Iterator iterator() { return new Iterator() { protected Node ptr=head; public boolean hasNext() { return ptr!=null; } public Object next() { if(ptr!=null) { Object elt=ptr.elt; ptr=ptr.next; return elt; } else throw new NoSuchElementException(); } }; } }
    Processed: 0.017, SQL: 9