public class MyLinkedList<E> { transient MyNode first = null; transient int size =0; Object[] obs = null; MyLinkedList(Object[] obs){ this.obs = obs; MyNode preNode = null; for (int i = 0; i < obs.length; i++) { MyNode succ = new MyNode(preNode,(E)(obs[i]),null); if(preNode!=null){ preNode.next=succ; }else { first=succ; } preNode = succ; size++; } } class MyNode{ E w; MyNode pre = null; MyNode next=null; public MyNode(MyNode pre,E w, MyNode next) { this.w = w; this.next = next; this.pre=pre; } } public int length(){ return size; } }
时间: 2024-10-07 15:56:19