Java Sequential table

Source: Internet
Author: User

Want to see the Java version of the data structure, to understand some of the tree operations, write a sequential table familiar with

1  Packagecom.sqlist;2 3 /**4  * @authorXiangfei5 * Define a sequential table6  *7  */8  Public classSqllist {9     Final intDeflen = 10;Ten     intMaxLen; One     intCurlen; A Object elements[]; -      -     /** the * Default constructor method -      */ -      Publicsqllist () { -MaxLen =Deflen; +Curlen = 0; -elements =NewObject[maxlen]; +     } A     /** at * Initialize a data table based on one data and maximum length -      * @paramArray -      * @paramMaxLen -      */ -      PublicSqllist (Object array[],intmaxlen) { -          This. MaxLen = array.length > MaxLen?Array.length:maxlen; inCurlen =Array.Length; -elements =Newobject[ This. MaxLen]; to          +         //Copy -          for(inti = 0; i < MaxLen; i++){ theElements[i] =Array[i]; *         } $     }Panax Notoginseng     /** -      * @paramsqllist the * Copy Construction method +      */ A      Publicsqllist (sqllist sqllist) { the          This. MaxLen =Sqllist.maxlen; +          This. Curlen =Sqllist.curlen; -         //with a deep copy here . $elements =Newobject[ This. MaxLen]; $         //Copy -          for(inti = 0; I < This. MaxLen; i++){ -Elements[i] =Sqllist.elements[i]; the         } -     }Wuyi     /** the * Insert element position to specified position -      * @paramelement Wu      * @paramposition -      * @return About      */ $      Public BooleanInsertelement (Object element,intposition) { -         if(Position < 0 | | position >=maxlen) -             return false; -         Else{ A             inti = curlen-1; +              while(I >position) { theElements[i] = elements[i-1]; -             }  $Elements[position] =element; the             return true; the         } the     } the     /** - * Delete the element at the specified location in      * @paramposition the      * @return the      */ About      PublicObject Deleteelement (intposition) { the         if(Position < 0 | | position >=Curlen) the             return NULL; the         Else{ +Object Elementdel =Elements[position]; -             inti =position; the              while(I <Curlen) {BayiElements[i] = elements[i + 1]; the             } the             returnElementdel; -         } -     } the     /** the * Print all the elements the      */ the      Public voidshowsqllist () { -          for(inti = 0; i < Curlen; i++) the         { theSystem.out.print (elements[i].tostring () + ""); the         }94     } the}

Test class (Only one construction method is measured here, other methods are also very coarse)

1  Packagecom.sqlist;2 3 /**4 * Test Order table5  * @authorXiangfei6  *7  */8  Public classSqllisttest {9      Public Static voidMain (String args[]) {TenInteger array_int[] =NewInteger[]{1, 2, 3}; OneSqllist sqllist =NewSqllist (Array_int, 3); A  - sqllist.showsqllist (); -     } the}

Java Sequential table

Related Article

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.