超级数组,list底层实现模仿
来源:互联网 发布:程颢 知乎 编辑:程序博客网 时间:2024/05/09 12:31
public class SuperArray { // 定义属性 private int[] array = new int[20]; //数组中已经存放的元素 private int size; // 定义行为 // 增加 public void add(int values) { if (this.size < this.array.length) { this.array[this.size] = values; this.size++; } else { int[] newArray = new int[this.array.length + 10]; System.arraycopy(array, 0, newArray, 0, this.array.length); this.array = newArray; this.add(values); } } // 删除 public void delete(int index) { if (index < this.size && index >= 0) { for (int i = index; i < this.size - 1; i++) { this.array[i] = this.array[i + 1]; } this.size--; } if (this.array.length > 20 && (this.array.length - this.size) > 10) { int[] newArray = new int[this.array.length - 10]; System.arraycopy(array, 0, newArray, 0, this.array.length - 10); this.array = newArray; } } // 查询 public int get(int index) { if (index >= 0 && index < this.size) { return this.array[index]; } throw new ArrayIndexOutOfBoundsException(); } // 修改 public void set(int index, int values) { if (index >= 0 && index < this.size) { this.array[index] = values; } } // 输出元素个数 public int size() { return this.size; }}
0 0
- 超级数组,list底层实现模仿
- 模仿QueryRunner的底层实现
- List集合底层实现
- 自己实现一个ArrayList,模仿ArrayList类的底层结构
- duilib模仿实现list ctrl的icon
- PHP的数组底层实现
- PHP的数组底层实现
- 【视频】超级模仿
- vector list deque set map-底层实现
- 使用数组和底层容器实现栈
- stack 底层简单实现 动态数组
- 栈和队列的底层数组实现
- List接口常用实现类的特点和底层实现
- c++list模仿
- java 数组实现迭代方法 iterator,模仿Arraylist
- C++中 vector、list、deque、set、map的底层实现
- stl容器区别: vector list deque set map-底层实现
- Erlang list的++操作和append函数的底层实现
- 代理模式
- java重命名失败
- Eclipse安装插件的几种方式
- Oracle数据库表空间大小不足问题
- 编码和过滤器
- 超级数组,list底层实现模仿
- 使用smartUpload上传附件
- 交叉编译 ffmpeg
- HDU1058 Humble Numbers 【数论】
- 打印目录下所有文件 迭代方法实现
- QList介绍
- 测试
- 中序遍历二叉树
- document获取节点ByName和ByTagName