public class SuperArray {
//数组存放
private int[] elments;
//使用构造器
public SuperArray(){
//elments=new int[10];
this(10);
}
//维护当前存储的位置
private int currentIndex=-1;
public SuperArray (int capacity){
elments=new int [capacity];
}
//实现数据的增删改查
//增加数据
public void add (int data){
//游标++
currentIndex++;
//扩容
if(currentIndex>elments.length-1){
int[]temp=new int[elments.length*2];
for (int i = 0; i < elments.length ; i++) {
temp[i]=elments[i];
}
elments=temp;
}
}
//删除
public void delete (int index){
for (int i =index ; i <elments.length ; i++) {
elments[i-1]=elments[i];
}
currentIndex--;
}
//改
public void set (int index,int data){
elments[index]=data;
}
//查
public int select (int index){
return elments[index];
}
//获取长度
public int set(){
return elments.length;
}
}
public class Text {
public static void main(String[] args) {
SuperArray superArray=new SuperArray();
superArray.add(12);
superArray.add(120);
superArray.add(123);
superArray.delete(2);
for (int i = 0; i < superArray.set() ; i++) {
System.out.println(superArray.select(i));
}
}
}
"C:\Program Files\jdk-11.0.4\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2021.2\lib\idea_rt.jar=59047:C:\Program Files\JetBrains\IntelliJ IDEA 2021.2\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\HY\IdeaProjects\out\production\encapsulation com.ydlclass.entity.homework.Text
0
0
0
0
0
0
0
0
0
0
Process finished with exit code 0