java 实现简易List列表

来源:互联网 发布:软件研制总结报告 编辑:程序博客网 时间:2024/05/29 19:10
public class MyList<T> {    private int size;    private Node head;    private Node end;    class Node{        public T data;        public Node next;    }    public void add(T t){        size++;        Node node = new Node();        node.data = t;        if (head==null){            this.head = node;        }else{            end.next = node;        }        end = node;    }    public int size(){        return size;    }    public T get(int i){        Node p = head;        for (int j= 0;j<i; j++){            p = p.next;        }        return p.data;    }}

原创粉丝点击