Java Basics-Linear table Basic Concepts __java

Source: Internet
Author: User

From the logical structure of data, the relationship between data elements is called the logical structure of data. To sum up, the data in the application has roughly four basic logical structures:

1, set: the relationship between data elements "belong to one set"

2. Linear structure: There is a relationship between data elements.

3. Tree structure: There is a relationship between data elements.

4. Graph or mesh structure: there are multiple relationships between data elements.


For the commonly used data structure, it can be simply divided into linear structure and nonlinear structure. The linear structure is mainly linear, and the nonlinear structure is mainly tree and graph. This discussion of linear tables.


The linear table (Linear list) is an ordered sequence composed of N (n >= 0) data elements (nodes) a1a2a3a4......an.

Each element in a linear table must have the same structure (that is, it has the same data item). Linear table is the simplest and most commonly used data structure in linear structure. Many people tend to interpret the data elements of a linear table as simple data items. The following figure shows a linear table.

Employee Number name Age Education
0001 Monkey king 500 Specialist
0002 Pig 400 Undergraduate
0003 Sand Monk 300 Undergraduate
0004 Tang Sanzang 40 Master
...... ...... ...... ......

For the data in the table above, it is still essentially a linear table, but each of his data elements is a "conforming" object, with each data element including four data items (also known as field): Employee number, name, age, education.


A linear table can also have the following definitions:

1, the linear table contains the number of data elements n is called the length of the table, when the length of the linear table is 0 o'clock the table is also called empty table.

2, when n > 0 o'clock, the table can be expressed as: (a1,a2,a3,a4,a5,......an)


For a non-empty, finite linear table, it always has the following basic characteristics :

(1), there is always a unique "first" data element.

(2), there is always a unique "last" data element.

(3), except for the first data element, each data element in the collection has only one precursor data element.

(4), except for the last data element, each data element in the collection has only one subsequent data element.

(The concept of precursors and successors can be searched for books on topological ordering in the graph).


To implement a linear table, the program first needs to determine each data element of the linear table. Next, you should implement the following for the linear table:
(1), initialization: Usually a constructor for creating an empty linear table.

(2), returns the length of the linear table: The method is used to return the number of data elements in the linear table.

(3), gets the element at the specified index: Returns the data element from the linear table based on the index.

(4) The location of the data element by value: if there is one or more data elements in the linear table that are equal to the lookup value, then the method returns the index of the first data element to which the value of the search is equal, or 1 if not.

(5) Directly inserting data elements: inserting a data element into the head of the linear table, the length of the linear table + 1,

(6) inserting an element at a specified position: Inserts a data element into the specified index of the linear table, the length of the linear table + 1,

(7), delete data elements directly: Delete the linear table head data elements, linear table length-1.

(8) Deletes the data element at the specified index in the linear table: Deletes the data element at the specified index in the linear table, and the length of the linear table-1.

(9), to determine whether the linear table is empty: The method to determine whether the linear table is empty, if the linear table is empty, return true, if not NULL, return FALSE.

(10), Empty the linear table: empty the linear 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.