Java algorithm--sequential table

Source: Internet
Author: User

sequential table structure definition : is a linear table stored in sequential storage mode

11. Defines the basic data for a sequential table:2  3 Static Final intMaxLen = 100;4  5 Class student{6     PrivateString number;//Students ' study number7     PrivateString name;//Student Name8     Private intAge//Student Age9 }Ten   One Class slt{ Astudent[] ListData =NewStudent[maxlen];//define a student array to hold students -     intListlen;//Current Array -}
2. Operation of the sequential table * * Pay attention to the situation of critical point
    • Initialization Order Table
    • Get the length of a sequential table
    • Inserting data into a sequential table
    • Append node
    • Delete a node
    • Find node 1) Find Node 2) find the node for the corresponding school number
    • Show all nodes
1  //1) Initialization order table2      Public voidinitslt (SLT sl) {3Sl. Listlen = 0;4 }    5    //2) Get the sequential table length6  Public intsllength (SLT sl) {7     returnSL. Listlen;8 }    9    //3) Inserting nodes into the order tableTen      Public BooleanINSERTSLT (SLT SL,intN, Student Stu) { One     BooleanJudge =false; A     if(n<0 | | n>sl. ListLen-1){ -SYSO ("The insertion data point position number is incorrect");  -     return false; the }     -        if(SL. Listlen >maxlen) { -SYSO ("The Order table is full"); -         return false; + } -          for(intI=0;i<sl. listlen-1;i++){ +             if(i = =N) { A              //the part of the n+ moves backwards. at              for(intJ=sl. ListLen-1;j>n; J-- ){ -Sl. LISTDATA[J] = sl. Listdata[j-1];  - }        - } - }       -Sl. Listdata[n] =Stu;  inSl. Listlen + +; -     return true; to } +    //4) Append node -       Public BooleanStladd (STL sl,student stu) { the     *     if(SL. Listlen >maxlen) { $SYSO ("The order table is full and cannot be added");Panax Notoginseng     return false; - } the         +Sl. Listdata[sl. Listlen + 1] =Stu; A   the } +      -    //5) Delete node $     Public BooleanStldelte (STL SL,intN) {   $      if(n<0 | | n>sl. ListLen-1){ -SYSO ("The insertion data point position number is incorrect");  -         return false; the     }     -     if(SL. Listlen<=0){WuyiSYSO ("No data in the order table can be deleted"); the     return false; - }     Wu      for(intI=0;i<sl. listlen-1;i++){ -     if(i = =N) { About      for(intJ=n;j<sl. listlen;j++){ $Sl. listdata[j]= SL. Listdata[j+1] - } -   - } ASl. Listlen--; +   the }     - }     $     //6) Finding nodes the      PublicData Searchdatabynumber (STL SL, String number) { the     inti; the     if(I=1; i<sl. listlen;i++){ the     if(SL. Listdata[i].number.equal (number)) { -     returnSL. Listdata[i]; in}Else the     { the     return NULL; About } the }    the } the    //7) Show all nodes +         Public voidStlall (STL sl) { -         inti; the          for(I=0;I&LT;SL. ListLen-1; i++){BayiSYSO ("content of the output book node"); the     }     the   -}

Java algorithm--sequential 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.