實現的myarraylist實為順序表結構,其中要實現iterable時必須在內部實現iterator,即為該表的迭代器.
1public
class myarraylistimplements iterable
6private
class myiterator implements iterator
1415
@override
16public
anttype next()
21public
void
remove()24}
2526
private
static
final
int default_capacity = 10; //
設定預設容量
2728
private
int thesize; //
當前大小
29private anttype theitems; //
元素物件陣列
3031
public myarraylist()
3435
public
void clear()
3940
public
void ensurecapacity(int newcapacity )46}
4748
public
int size()
5152
public
boolean isempty()
5556
public
void trimtosize()
5960
public anttype get(int
idx)
6768
//替換元素
69public anttype set(int
idx, anttype newval)
7677
public
boolean add( anttype newval)
8384
public
void add( int idx, anttype newval)
9293
public anttype remove(int
idx)
98 thesize--;
99return
val;
100}
101 }
3 4 MyArrayList 類的實現
這節提供一個便於使用的 myarraylist 泛型類的實現,這裡不檢測可能使得迭代器無效的結構上的修改,也不檢測非法的迭代器 remove 方法。 myarraylist 將保持基礎陣列,陣列的容量,以及儲存在myarraylist 中的當前項數。 myarraylist 將提供一種機制以改變基礎...
求鏈式表的表長
本題要求實現一個函式,求鏈式表的表長。 int length list l 其中list結構定義如下 typedef struct lnod...
46 表與表的連線
一 主鍵 primary key 1 1 從約束條件上看,等同於not null unique 非空且唯一 create table t1 id int primary key 1 2 主鍵除了有約束效果外,還是innodb儲存引擎組織資料的依據 innodb儲存引擎在建立表的時候必定會有prima...