package array;
/**
* 线性查找算法
* <pre>
* 循环依次从最后一位到第一位(或从第一位到最末位)依次查找
* </pre>
* @author 杨伦亮
* 1:14:56 AM
*/
public class HighArray implements Find{
private long[] a;
private int nElement;
/**构建函数*/
public HighArray(int max) {
a = new long[max];
nElement = 0;
}
/**查找值*/
public Object find(long searchValue){
int j;
for ( j = 0; j < nElement; j++) {
if(a[j]==searchValue){
break;
}
}
if(j==nElement){
return false;
}else {
return true;
}
}
/**增加值*/
public void insert(long value){
a[nElement]=value;
nElement++;
}
public int getSize(){
return nElement;
}
/**删除指定值*/
public boolean delete(long value){
int j;
for (j = 0; j < nElement; j++) {
if(a[j]==value){
break;
}
}
if(j==nElement){
return false;
}else {
for (int k = j; (k+1) < nElement; k++) {
a[k]=a[k+1];
}
nElement--;
return true;
}
}
/**显示*/
public void display(){
for (int i = 0; i<nElement; i++) {
System.out.print(a[i]+" ");
}
System.out.println();
}
}