网站开发过程中出现的问题,企业wordpress模板免费,怎么封锁网站,教育类网站源码自定义数组(面向对象编程)#xff1a;直接上代码#xff1a;package com.xingej.algorithm.datastructure.array;/*** 面向对象编程** 自定义类数组** 你一定要明白#xff0c;这是在JDK基础之上的封装#xff0c;要学会这种思路#xff0c;其他框架如netty 也是在前者的基…自定义数组(面向对象编程)直接上代码package com.xingej.algorithm.datastructure.array;/*** 面向对象编程** 自定义类数组** 你一定要明白这是在JDK基础之上的封装要学会这种思路其他框架如netty 也是在前者的基础上封装而来的如有一** 部分是封装的线程池** author erjun 2017年11月28日 下午9:42:10*/public class MyArray {// 定义的数据结构类型是 数组// 这是最核心的组件其他都是围绕这个来进行操作的private long[] arr;// 表示有效数据的长度也就是说数组里有多少个数组private int elements;public MyArray() {// 默认可以存储50个数字arr new long[50];}public MyArray(int maxsize) {arr new long[maxsize];}// 插入数据public void insert(long value) {arr[elements] value;// 每次插入数据都会自增一次elements;}// 根据索引来查找数据public long get(int index) {if (index elements || index throw new ArrayIndexOutOfBoundsException();}return arr[index];}// 显示数据也就是打印数组里的内容public void display() {// 说明此时数组里还没有内容呢if (elements 0) {return;}System.out.print([ );for (int i 0; i System.out.print(arr[i] );}System.out.println(]);}// 根据输入的值来返回 索引值public int getIndexByValue(long value) {int i 0;for (; i if (arr[i] value) {// 如果找到的话就立即返回索引值return i;}}return -1;}// 根据索引值来删除数组里的元素public void delete(int index) {if (index elements || index throw new ArrayIndexOutOfBoundsException();}// 将后面的元素往前移动for (int i index; i arr[i] arr[i 1];}// 最后将有效值减一elements--;}// 更新值public void update(int index, long newValue) {if (index elements || index throw new ArrayIndexOutOfBoundsException();}arr[index] newValue;}}测试用例package com.xingej.algorithm.datastructure.array;import org.junit.Before;import org.junit.Test;import com.xingej.algorithm.datastructure.array.MyArray;/*** 面向对象编程** 也就是说你操作的 都是对象而非基本数据类型了*** author erjun 2017年11月28日 下午9:59:36*/public class MyArrayTest {private MyArray myArray;Beforepublic void init() {myArray new MyArray();testInsert();}// 插入数据测试Testpublic void test() {myArray.insert(20);System.out.println(----:\t myArray.get(0));}Testpublic void testInsert() {myArray.insert(20);myArray.insert(10);myArray.insert(5);myArray.insert(30);}// 显示/打印数组里的内容Testpublic void testDisplay() {myArray.display();}// 显示/打印数组里的内容Testpublic void testGetIndexByValue() {System.out.println(---索引值是:\t myArray.getIndexByValue(20));}// 根据下标来删除指定位置的元素Testpublic void testDelete() {System.out.println(---删除之前打印数组里的元素------);myArray.display();myArray.delete(5);System.out.println(---删除之后打印数组里的元素------);myArray.display();}Testpublic void testUpdate() {myArray.update(2, 100);System.out.println(---更新之后的值----\t myArray.get(2));}}代码已经上传到git上了