Linear table (list)

Source: Internet
Author: User

1. What is a linear table (list)?

A finite sequence of 0 or more data elements.

(1) The elements are ordered.

(2) Linear table emphasis is limited.

2. What are the actions of the linear table?

(1) Creation and initialization of linear tables, initlist

(2) empty, Listempty (), true-

(3) Linear table reset to Empty table, Clearlist ()

(4) Get the value of the position of the linear table I, Getelem (int i)

(5) Finding a node with a value of x in a linear table,locateelem (int x)

(6) inserting a node with a value of x in the linear table, insertelem (int x,int i)

(7) Delete the first node of the linear table,deleteelem (int i)

(8) to find the length of the linear table,listlength ()

(9) determine if the linear table is full, listfull ()

public class Linearlist {private int[] data;//linear table holds the maximum extent of the private int maxsize;//table space as an array private int last; The table's current number of nodes, which is the table length//constructor public linearlist (int MaxSize) {if (maxsize>0) {this}.              MaxSize = MaxSize;              last = 0;          CREATE TABLE space data = new int [MaxSize];      }}//Determine if the linear table is empty public boolean listempty () {return (last <=0)? True:false;      }//Determine if the linear table is full public boolean listfull () {return (last >= MaxSize)? True:false;      }//To find the length of the linear table public int listlength () {return last;          }//Find the value of the I node in the linear table public int Getelem (int i) {///if present, return the node, otherwise, return null; Return (i<0| |      i>last)? Null:data[i]; }//Find the node with the value x in the linear table, public int locateelem (int x) {//Find the node with the value X in the lookup table, and return the ordinal of that node, or return 1;//If there are multiple nodes with a value of x in the table          , find the front one; for (int i=0;i<last;i++) {if (data[i] = = x) return i; } return-1; }//Insert a node with a value of x in the linear table the public boolean insertelem (int x,int i) {//Insert a node with a value of x in the table I/O//If the insert succeeds, return T Rue, otherwise return false//insert position unreasonable, insert failed if (i<0| | i>last| |          last = = MaxSize) return false;              else {//move back for (int j = last;j>i;j--) data[j] = data[j-1];              Insert data[i] = x;              The length of the table increases by one last++;                      return true;          }}//delete the first node of the linear table public boolean deleteelem (int i) {//delete the first node in the table, if successful, return true; otherwise return false; The first node does not exist, the deletion fails; if (i<0| | i>=last| |          last = = 0) return false;              else {//move forward for (int j=i;j<last-1;j++) data[j] = data[j+1];              Table length minus 1 last--;          return true; }} public void display () {System.out.println ("current linked listLength: "+ listlength ());          for (int i=0;i<last;i++) {System.out.println ("+i+" node is: "+data[i]);   }      }

  

Linear table (list)

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.