"Data Structure" array operation (Lowarrayapp.java)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.