1 //Lowarrayapp.java2 //demonstrates array class with low-level interface3 //To run this Program:c>java lowarrayapp4 //Java Data Structures and Algorithms (second edition) Marquez PDF 46th page Group Operations5 6 PackageFirst ;7 8 classLowarray9 {Ten Private Long[] A;//ref to array a One A PublicLowarray (intSize//Constructor -{a =New Long[Size]; }//Create array - the Public voidSetelem (intIndexLongValue//Set Value -{A[index] =value;} - - Public LongGetelem (intIndex//Get Value +{returnA[index];} - +}//End Class Lowarray A at - Public classLowarrayapp - { - Public Static voidMain (string[] args) - { -Lowarray arr;//Reference inarr =NewLowarray (100);//Create Lowarray Object - intNelems = 0;//Number of items in array to intJ//Loop Variable + -Arr.setelem (0, 77); theArr.setelem (1, 99); *Arr.setelem (2, 44); $Arr.setelem (3, 55);Panax NotoginsengArr.setelem (4, 22); -Arr.setelem (5, 88); theArr.setelem (6, 11); +Arr.setelem (7, 00); AArr.setelem (8, 66); theArr.setelem (9, 33); +Nelems = 10;//Now items in array - $ //Display Items $ for(j = 0; J < Nelems; J + +) -System.out.print (Arr.getelem (j) + ""); -System.out.println (""); the - //Search for data itemWuyi intSearchkey = 26; the for(j=0; J < Nelems; J + +) - if(Arr.getelem (j) = =Searchkey) Wu Break; - if(J = =nelems) AboutSystem.out.println ("Can ' t find" +searchkey); $ Else -System.out.println ("Found" +searchkey); - - //Delete Value A for(j = 0; J < Nelems; J + +) + if(Arr.getelem (j) = = 55) the Break; - $ for(intK = J; K < Nelems; k++)//the deleted data item is moved forward one after the other theArr.setelem (k, Arr.getelem (k+1)); thenelems--; the the //Display Items - for(j = 0; J < Nelems; J + +) inSystem.out.print (Arr.getelem (j) + ""); theSystem.out.println (""); the About}//End Main () the}//End Class Lowarrayapp
Operation Result:
The 0- Can
"Data Structure" array operation (Lowarrayapp.java)