从零单排List(一)----设计目标

目标:构建一个List

先看List是什么,jdk里的定义如下:
An ordered collection (also known as a sequence) The user of this interface has precise control over where in the list each element is inserted. The user can access elements by their integer index (position in the list), and search for elements in the list.
简单的说就是一个有序的集合:
1.用户可以对其中每个元素的插入位置进行精确地控制。
2.用户可以根据元素的整数索引(在列表中的位置)访问元素,并搜索列表中的元素。
归纳为:设计一个数据容器,支持随机或者顺序增删改查。

二话不说,先上代码:

public class MyList{

    public boolean add(Object e) {
        return false;
    }
    
    public boolean remove(Object o) {
        return false;
    }

    public Object get(int index) {
        return null;
    }

    public Object set(int index, Object element) {
        return null;
    }

    public void add(int index, Object element) {
        
    }

    public Object remove(int index) {
        return null;
    }

    public int indexOf(Object o) {
        return 0;
    }
}

具体实现,请看下回分解

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容