经典安全数组实现
2013-01-09 09:28
169 查看
final class DataSources {
private int size;
private DataSource[] data = new DataSource[4];
final int size(){
return size;
}
final DataSource get(int idx){
if (idx >= size)
throw new IndexOutOfBoundsException("Index: "+idx+", Size: "+size);
return data[idx];
}
final void add(DataSource table){
if(size >= data.length ){
DataSource[] dataNew = new DataSource[size << 1];
System.arraycopy(data, 0, dataNew, 0, size);
data = dataNew;
}
data[size++] = table;
}
}
private int size;
private DataSource[] data = new DataSource[4];
final int size(){
return size;
}
final DataSource get(int idx){
if (idx >= size)
throw new IndexOutOfBoundsException("Index: "+idx+", Size: "+size);
return data[idx];
}
final void add(DataSource table){
if(size >= data.length ){
DataSource[] dataNew = new DataSource[size << 1];
System.arraycopy(data, 0, dataNew, 0, size);
data = dataNew;
}
data[size++] = table;
}
}
相关文章推荐
- 入门经典_Chap06_例题[一]:队列,栈,链表的数组实现
- 面试宝典 经典笔试 题 之用 java 实现 旋转数组
- POJ 3928 Ping pong【树状数组经典难点实现】PS
- 第十七章经典抽象数据结构二:树(数组实现)
- 经典数据结构--数组实现的栈
- 【LeetCode-面试算法经典-Java实现】【189-Rotate Array(旋转数组)】
- 经典抽象数据类型之堆栈实现(动态数组)
- 【LeetCode-面试算法经典-Java实现】【027-Remove Element(删除数组中指定的元素)】
- 【LeetCode-面试算法经典-Java实现】【004-Median of Two Sorted Arrays(两个排序数组的中位数)】
- 经典数据结构之数组实现的队列
- Java通过几种经典的算法来实现数组排序
- 入门经典_Chap06_例题[二]:二叉树的指针及数组实现
- 经典面试题:求数组的最大子序列和;实现函数 :判断一个自负喜欢是否是另一个字符串旋转所得;杨氏矩阵中查找一个数。
- 【LeetCode-面试算法经典-Java实现】【033-Search in Rotated Sorted Array(在旋转数组中搜索)】
- 约瑟夫环的数组实现 __ 经典思考题原创解法.
- 九宫格 Swift提供经典的数组和字典两种集合类型来存储集合数据,使用数组实现一个九宫格程序,
- 【LeetCode-面试算法经典-Java实现】【088-Merge Sorted Array(合并排序数组)】
- 数据结构 多线程安全队列基于数组实现
- 【LeetCode-面试算法经典-Java实现】【053-Maximum Subarray(最大子数组和)】