1. As one of Java's most common data structures, the use of arrays is relatively simple, showing the number of comparisons that are commonly used by arrays in cases where duplicate values are allowed and not allowed
2. After the encapsulated code:
1 PackageCom.cn.higharray;2 /**3 * Further encapsulation of the array, more convenient to call.4 * @authorAdministrator5 *6 */7 Public classHigharray {8 Private Long[] A;9 Private intNelems;Ten PublicHigharray (intmax) { OneA =New Long[Max]; ANelems = 0; - } - Public BooleanFindLongkey) { the intJ; - for(j = 0;j<nelems;j++) - if(A[j] = =key) - Break; + if(J = =nelems) - return false; + Else A return true; at } - Public voidInsertLongvalue) { -A[nelems] =value; -nelems++; - } - Public BooleanDeleteLongvalue) { in intJ; - for(j = 0;j < Nelems;j + +) to if(A[j] = =value) + Break; - if(J = =nelems) the return false; * Else{ $ for(intK = J;k < Nelems;k + +)Panax NotoginsengA[k] = a[k+1]; -Nelems--; the return true; + } A } the Public voiddisplay () { + for(intj = 0;j < Nelems;j + +) - System.out.print (A[j]); $System.out.println (""); $ } -}
Java Data Structure----Array Chapter