The definition of linear table and its sequential storage structure

Keep creating and accelerate growth! This is the 29th day that I have participated in the "Nuggets Daily New Plan·October Update Challenge". Click to view event details

linear table

What is a linear table

A linear table is a table in which the data elements are arranged like a line (it sounds like nonsense, hahaha!!!, but it doesn't seem wrong). Strictly speaking, a linear list is a finite sequence of data elements with the same characteristics.

Characteristics of linear tables

  • All data elements are of the same type
  • A linear table consists of a finite number of data elements
  • The data elements in the linear table are position-related, that is, each data element has a unique serial number. This shows that the linear table is different from the set. The same data elements can appear in the linear table (their serial numbers are different), but not in the set. Data elements with the same value appear.

Linear table logical structure representation

The logical structure of the linear table is relatively simple, generally expressed as (a0, a1, a2, a3, a4, a5, a6,···, ai-1, ai,···, an-1) as shown in the figure :

09be3c660dfa20fbeb851ee219ee3af.jpg- Note: The unique position of each element ai in the linear table is represented by the serial number or index i. i generally starts from 0, so that the serial number i of a linear table containing n elements satisfies 0<=i<=n-1; where n It represents the length of the linear table. When n=0, it means that the linear table is an empty table and does not contain any data elements. - As can be seen from the figure, each element in a linear table has at most one predecessor element and at most one successor element. The first element has no predecessor elements. The tail element has no successor elements.

Abstract data type description of linear table

Abstract data type description of linear table: ADT List { //数据对象: D={ai|0<=i<=n-1,n>=0,ai为E类型} //E指的是用户指定类型 //数据关系: r={<ai,ai+1>|ai,ai+1∈D,i=0,···,n-2} //基本运算 E GetElem(int i):求线性表中序号为i的元素。 void SetElem(int i,E e):设置线性表中序号i的元素值为e void swap(int i ,int j):交换线性表中序号为i和序号为j的元素 //········

Sequential storage structure of linear table

Sequential storage is the most commonly used storage method for linear tables. It directly maps the logical structure of the linear table to the storage structure, so it is easy to understand and implement.

Sequence table

线性表的顺序存储结构是把线性表中的所有元素按照其逻辑顺序依次存储到计算机存储器中。线性表的顺序存储结构成为顺序表。

ba693cdc047db563457eda661b938a4.jpg- Capacity: The capacity of the array (the maximum number of elements stored) - Code example:

```java public class SqlListClass //Sequence table generic { final int initcapacity=10; //Initial capacity of the sequence table public E[] data; //Storage elements in the sequence table public int size; //Storage sequence table The length public int capacity; //Storage capacity of the sequence table public SqlListClass() //Construction method to implement initialization of data and length { data=(E[]) new Object[initcapacity]; //Forced conversion to E type array capacity =initcapacity; size=0; }

//顺序表基本算法

} ```

Guess you like

Origin blog.csdn.net/y943711797/article/details/132972200