Part of the data structure of linear form - Array

1, a linear type definition table

① linear structural features

在数据元素的非空有限集合中:
(1)存在唯一的一个被称做“第一个”的数据元素;
(2)存在唯一的一个被称做“最后一个”的数据元素;
(3)除第一个之外,集合中的每个数据集元素均只有一个前驱;
(4)除最后一个之外,集合中每个数据元素君之忧一个后继。

② concept of linear form

一个线性表是n个数据元素的有限序列,数据元素可以是单个字母字符,如:	

(A,B,C,…,Z)

是一个线性表,数据元素也可以由若干个数据项组成,但同一线性表中的元素必定具有相同的特性,即属同一数据对象,相邻的数据元素之间存在着序偶关系,若将线性表标记为

(A1, ..., a i-1 , a i , a i + 1 , ..., a n )

A i is the i th element of the table, said data element i A i bit sequence in the data line.

2, the table indicates the order linear

It represents a linear sequence table refers to a set of Address of the contiguous memory locations storing a linear table data elements.
Each element of the table needs to assume a linear accounted l memory cells, and to store the address of the first unit as the storage location occupied by data elements. The first linear table i + 1 stored in the location data elements the LOC (A i + 1 ) and i stores the location data elements the LOC (A i satisfy the following relationship between a):

LOC (a i + 1 ) = LOC (a i ) + l

In general, the linear form of the i th storage location of the data elements:

LOC (a i ) = LOC (a 1 ) + (i - 1) * l

Linear structure is stored in this tableOrder tableIt is characterized by, the data elements within the computer "Physical location adjacent" to represent logical relationships between tables of data elements in the orderStoring each data element positions are linear, and the starting position of the table differ by a constant and proportional to the bit line of the data elements in the sequence table, thereby determining the start position is stored as long as the linear form, the linear form element can be any of a random access data, the order table is a linear structureRandom AccessThe storage structure.

由于高级程序设计语言中的数组类型也有随机存取的特性,因此通常都用数组来描述数据结构中的顺序存储结构。

3, a schematic view of the structure

Here Insert Picture Description

4, an array of additions and deletions

① new element

Because adjacent logic elements are adjacent on the physical location, so in order to insert the element after the element 3 5, it is necessary to have all the elements after the shift diagram is as follows:
Here Insert Picture Description

② remove elements

Similarly, after removing elements 5, all the elements need to be moved forward after the element 5, a schematic diagram is as follows:
Here Insert Picture Description

5, summary

(1) an array of support random access, so the array elements of the query fast;
deletions (2) the need to move large amounts of data array elements (in most cases), so add or delete elements in the array is very slow.

Published 12 original articles · won praise 12 · views 60000 +

Guess you like

Origin blog.csdn.net/SGdan_qi/article/details/104366567