package shujujiegou;
public class Array {
public static void main(String[] args) {
Array a = new Array();
/* int[] array = new int[8];
array[0] = 10;
array[1] = 11;
array[2] = 12;
array[3] = 13;
array[4] = 14;
final int[] insert = a.insert(array, 2, 7,6);
for (int i = 0; i <insert.length ; i++) {
System.out.println(insert[i]);
}*/
int[] array2 = new int[10];
array2[0] = 10;
array2[1] = 11;
array2[2] = 12;
array2[3] = 13;
array2[4] = 14;
a.delete(2, array2);
for (int i : array2) {
System.out.println(i);
}
}
//往数据插入数据 index 位置 element数据
private int[] insert(int[] array, int index, int element,int size) {
//从右循环数组,当长度小于index时候,插入数据 让数组往后迁移一位
for (int i = size; i >=index ; i--) {
array[i]=array[i+1];
}
array[index]=element;
return array;
}
//删除数据
private void delete(int index, int[] array2) {
//需要把数都往前移动一位
int size=array2.length;
for (int i = index; i <size; i++) {
array2[i]=array2[i+1];
size--;
}
}
}