1 //Java data Structures and algorithms second Edition Marquez2 //operation of the array3 4 PackageFirst ;5 6 classHigharray {7 Private Long[] A;8 Private intNelems;9 Ten PublicHigharray (intmax) { OneA =New Long[Max]; ANelems = 0; - } - the Public voidInsertLongvalue) { -A[nelems] =value; -nelems++; - } + - Public voiddisplay () { + for(intj = 0; J < Nelems; J + +) { ASystem.out.print (A[j] + ""); at } -System.out.println (""); - } - - Public BooleanFindLongSearchkey) { - intJ; in for(j = 0; J < Nelems; J + +) - if(A[j] = = Searchkey) Break; to + if(J = =nelems) - return false; the Else * return true; $ }Panax Notoginseng - Public BooleanDeleteLongvalue) { the intJ; + for(j = 0; J < Nelems; J + +) A if(A[j] = = value) Break; the + if(J = =nelems) - return false; $ Else { $ for(intK = J; K < Nelems; k++) -A[k] = a[k + 1]; -nelems--; the return true; - }Wuyi } the}//end of class Higharray - Wu - Public classHigharrayapp { About Public Static voidMain (string[] args) { $ intmaxSize = 100; -Higharray arr =NewHigharray (maxSize); - -Arr.insert (77); AArr.insert (99); +Arr.insert (44); theArr.insert (55); -Arr.insert (22); $Arr.insert (88); theArr.insert (11); theArr.insert (00); theArr.insert (66); theArr.insert (33); - Arr.display (); in the intSearchkey = 35; the if(Arr.find (searchkey)) AboutSystem.out.println ("Found" +searchkey); the Else theSystem.out.println ("Can ' t Find" +searchkey); the +Arr.delete (00); -Arr.delete (55); theArr.delete (99);Bayi the if(Arr.delete (23429) = =false) theSystem.out.println ("Can ' t delete" + 23429); - - Arr.display (); the } the}//end of class Higharrayapp the the -
Operation Result:
2342977 44 22 88 11 66 33, 0/ t Find 35can ' t
"Data Structure" array operation (Higharrayapp.java)