package TestArray
;
/**
* Created by Administrator on 2017/5/3.
*/
public class HighArray {
int[]
a =
new int[
5]
;
int n =
0 ;
public void insert(
int value){
a[
n] = value
;
n++
;
if (
n ==
a.
length-
1){
int[]b=
new int[
a.
length*
2]
;
for (
int i =
0; i <
n ; i++) {
b[i]=
a[i]
;
}
a=b
;
}
}
public boolean find(
int key){
// 77 99
int i
;
for (i =
0; i <
n ; i++) {
if(
a[i] == key ){
//找到了
break;
}
}
if( i <
n ){
return true;
}
else{
return false;
}
}
/**
* 找到这个key所在的下标
* @param index
* @return
*/
public int findindex(
int index){
int j
;
for ( j =
0; j <
n ; j++) {
if (index==
a[j]){
return j
;
}
}
return -
1;
}
public void display() {
for (
int i =
0; i <
n; i++) {
System.
out.print(
a[i] +
" ")
;
}
}
public void delete(
int value){
int delIndex = findindex(value)
;
for (
int i = delIndex
; i <
n ; i++) {
a[i]=
a[i+
1]
;
}
n--
;
}
}
package TestArray
;
/**
* Created by Administrator on 2017/5/3.
*/
public class HighArrayApp {
public static void main(String[] args) {
HighArray arraylist =
new HighArray()
;
arraylist.insert(
77)
;
arraylist.insert(
99)
;
arraylist.insert(
33)
;
arraylist.insert(
55)
;
System.
out.print(
"您输入的数组为:")
;
arraylist.display()
;
System.
out.println()
;
System.
out.println(
"下标为:"+arraylist.findindex(
99))
;
arraylist.delete(
77)
;
System.
out.print(
"删除77以后的数组:")
;
arraylist.display()
;
System.
out.println()
;
for (
int i =
0; i <
88 ; i++) {
arraylist.insert(i)
;
}
arraylist.display()
;
}
}