迭代器Iterator

迭代器:容器与容器遍历。
容器:在物理层面上,存储结构只有两种,一种是连续位置存储就是数组 另一种是不连续存储就是链表
其他的任何数据结构底层都是由数组或者链表组成的。
实现自定义容器:
定义一个迭代器IteratorSelf
public interface IteratorSelf implementsCollectionSelf{
boolean hasNext();
Obejct next();
}
自定义一个数组容器
class ArrayListSelf{
Object[] objects = new Object[10];
private int index = 0;
public void add(Object o){
Object[] newObjects = new Object[objects.length*2];//动态扩容
System.arraycopy(objects,0,newObjects,0,objects.length);
objects = new Objects;
}
objects[index] = o;
index++;
}
public int size{return index;}
}

自定义一个链表容器
class LinkedListSelf implementsCollectionSelf{
Node head = null;
Node tail = null;
private int size = 0;
public void add(object o){
Node n = new Node(o);
n.next

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值