* 在第i个位置插入新元素
*/
public
boolean
ListInsert(
int
i,E e) {
if
(i<
1
||i>
this
.length+
1
) {
throw
new
RuntimeException(
"插入位置错误:"
+i);
}
if
(
this
.length==
this
.maxSize) {
/*1.无法继续插入*/
//System.out.println("表已满,无法继续插入!");
//return false;
/*2.增加容量*/
maxSize=maxSize+
10
;
Object[] newdata=
new
Object[maxSize];
for
(
int
k=
1
;k<=
this
.length;k++)
newdata[k-
1
]=
this
.data[k-
1
];
this
.data=newdata;
}
if
(i<=
this
.length) {
//插入数据不在表尾 **这个判断是否有必要呢?
for
(
int
j=
this
.length+
1
;j>i;j--)
this
.data[j-
1
]=
this
.data[j-
2
];
}
this
.data[i-
1
]=e;
this
.length++;
//表长改变勿忘
System.out.println(
"插入成功!"
);
return
true
;
}