Package Ch01;public class Myorderarray {private long [] arr;private int elements;//array true number public Myorderarray () {arr = new long[50];//the size of the default array is 50}public myorderarray (int maxsize) {arr = new long[maxsize];} method of inserting elements public void Insert (Long value) {int i;for (i=0;i<elements;i++) {if (Arr[i] > value) {break;}} for (int j = elements;j>i;j--) {Arr[j] = arr[j-1];} Arr[i] = value;elements++;} Dichotomy Lookup public int binarysearch (Long value) {int low = 0;int POW = elements;int middle = 0;while (true) {middle = (LOW+POW)/2; If the middle value is the value to find if (arr[middle] = = value) {return middle;} else if (Low > Pow) {return-1;} Else{if (Arr[middle] > value) {pow = middle-1;} Else{low = Middle+1;}}} The method that is displayed public void display () {System.out.print ("["); for (int i=0;i<elements;i++) {System.out.print (arr[i]+ "");} System.out.print ("]"); System.out.println ();} Find data method, find data based on value to find, return value of subscript public int search (Long value) {int i;for (i=0;i<elements;i++) {if (arr[i] = = value) {break;}} if (i = = elements) {return-1;} Else{return i;}} Find data, return values by index pUblic long get (int index) {//Determine if array is out of bounds if (Index < 0 | | Index >= elements) {throw new ArrayIndexOutOfBoundsException ("number Group out of Bounds ");} Else{return arr[index];}} Delete data public void Delete (int index) {if (Index >=elements | | Index < 0) {throw new ArrayIndexOutOfBoundsException (" Array out of Bounds ");} else{for (int i=index;i<elements;i++) {Arr[index] = arr[index+1];} The length of the array--elements--;}} Update data public void change (int index,int newvalue) {if (Index >= elements | | Index < 0) {throw new arrayindexoutofbounds Exception ();} else {Arr[index] = newvalue;}}}
Ordered Array 2