Java Language Establishment Order table

Source: Internet
Author: User

1  Packagedatastructure;2 //Linear Table3 4  Public InterfaceIList {5      Public voidClear ();6      Public BooleanisEmpty ();7      Public intlength ();8      PublicObject Get (intIthrowsException;9      Public voidInsertintI,object x)throwsException;Ten      Public voidRemoveintIthrowsException; One      Public intindexOf (Object x); A      Public voiddisplay (); -  -}
1  Packagedatastructure;2Sequential table3 4  Public classSqListImplementsIList {5     Privateobject[] Listelem;6     Private intCurlen;7      PublicSqList (intmaxSize) {8Curlen =0;9Listelem =NewObject[maxsize];Ten     } One      Public voidClear () { ACurlen=0; -     } -      Public BooleanIsEmpty () { the          -         returnCurlen==0; -     } -      Public intLength () { +          -         returnCurlen; +     } A      PublicObject Get (intIthrowsException { at         if(i<0| | I>curlen-1) -             Throw NewException ("+i+" element does not exist "); -          -         returnListelem[i]; -     } -      in      Public voidInsertintI, Object x)throwsException { -         if(curlen==listelem.length) to             Throw NewException ("Order table is full"); +         if(i<0| | I>Curlen) -             Throw NewException ("Invalid insertion position"); the          for(intj=curlen;j>i;j--) *Listelem[j]=listelem[j-1]; $listelem[i]=x;Panax Notoginsengcurlen++; -     } the      Public voidRemoveintIthrowsException { +         if(i<0| | I>curlen-1) A             Throw NewException ("Delete location is illegal"); the          for(intj=i;j<curlen-1;j++) +Listelem[j]=listelem[j+1]; -curlen--; $          $     } -      Public intindexOf (Object x) { -         intJ=0; the          while(j<curlen&&!listelem[j].equals (x)) -J + +;Wuyi         if(j<Curlen) the             returnJ; -         Else Wu         return-1; -     } About      Public voiddisplay () { $          for(intj=0;j<curlen;j++) -System.out.print (listelem[j]+ ""); - System.out.println (); -     } A      +}

Java Language Establishment Order table

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.