1. 程式人生 > >Java實現兩分彩源碼搭建操作

Java實現兩分彩源碼搭建操作

繼承 否則 接口 普通 避免 偶數 index 必須 this

一:兩分彩源碼搭建介紹:企 娥:217 1793 408

為了避免插入和刪除的線性開銷,就需要保證表可以不連續存儲,否則表的每部分可能都需要整體移動。Java語言中包含一些普通數據結構的實現,這部分叫做Collections API.
Collections API位於java.util包中,collection接口要註意它擴展了Iterable接口,實現Iterable接口的集合必須提供一個稱為iterator的方法,叠代器可以實現循環遍歷。List接口繼承了Collection接口。
線性時間刪除表中的偶數:

public static void removeEvens(List<Integer> lst){

Iterator<Integer> itr=lst.iterator();
while(itr.hasNext()){
if(itr.next()%2==0)
itr.remove();
}
}

上面代碼對ArrayList是二次的,但對LinkedList是線性的。
鏈表逆置:
定義結點:

1 public class Node {
2 int index;
3 Node next;
4 public Node(int index, Node next) {
5 this.index = index;
6 this.next = next;
7 }
8 }

Java實現兩分彩源碼搭建操作