Linear table (list)
Definition: A finite sequence consisting of 0 or more data elements.
Keywords
① sequence: It is a sequence, and the elements are sequentially
② If there are multiple elements: the first element has no precursor , the latter element has no successor, and the other element has only one precursor and subsequent
③ Limited.
The mathematical language is defined as follows
If the linear memento is (A1,...,ai-1,ai,ai+1,...,an), the table Ai-1 lead Ai,ai ahead of Ai+1, said Ai-1 is the direct precursor of AI, ai+1 is the direct successor of the AI elements
650) this.width=650; "title=" 11.jpg "src=" http://s3.51cto.com/wyfs02/M00/56/CA/wKioL1SOVvGTrQrSAACKl8qv6sc944.jpg "alt=" Wkiol1sovvgtrqrsaackl8qv6sc944.jpg "/>
The number of linear variable elements n (n>=0) is defined as the length of the linear table, when N=0 is, called the empty table .
Abstract data types
Definition of a data type: Refers to a set of properties of the same nature, and defines the general name of some operations on this set (such as Integer, float, etc.)
Data types in C can be divided into two categories
Atomic type: A basic type that can no longer be decomposed, such as Integer, float, character, and so on.
struct type: A combination of several types that can be decomposed, such as an integer array
abstract : Refers to extracting the nature of the universality of a transaction. It requires extracting the characteristics of the problem and ignoring the non-essential details, which is a generalization of things. Abstraction is a way of thinking, and it hides the intricacies of detail.
We abstract the existing data types, and we have abstract data types.
Abstract data type (ADT) refers to a mathematical model and defines a set of operations on the model
Meaning: Mathematical abstraction of data types
Standard format for abstract data types (pseudo-code):
ADT Abstract Data type
Data
Definition of logical relationship between data elements
Operation
Operation
Endadt
Abstract data type definitions for linear tables:
ADT Linear table (list)
Data:
The set of data objects for a linear table is {A1,A2,..., an}, and each element is of type datatype. wherein, in addition to the first A1, each of the meta-and only a direct precursor element, in addition to the last element an, each meta-and only a successor element, the data element is a one-to-ones relationship
Operation: Some of the following actions
initlist (*l): initialize operation, establish an empty linear table L
Listempty (L): Determine if the linear table is a null table, if the linear table is empty, return true, otherwise false
clearlist (*l): Empty the linear table
Getelem (l,i,*e): returns the first position element value in the linear table L to E
Locateelem (l,e): finds an element in the linear table L that is equal to the given value E, if the lookup succeeds, the return element in the table indicates success; otherwise, 0 indicates failure.
Listinsert (*l,i,e): inserts a new element in the linear table L in the first position E
Listdelete (*l,i,e): removes the i-position element in the linear table L and returns its value with E
listlength (L): Returns the number of elements of the linear table L
Endadt
Example: Implementing A=A∪B
The basic combination of operations we need to use
Listlength (L)--Returns the number of elements
Getelem (l,i,*e)--Returns the value of the I position element in the linear table L to E
Locataelem (L,e)--Finds an element in the linear table L that is equal to the given value E, if the lookup succeeds, the return element in the table indicates success; otherwise, a return of 0 indicates a failure.
Listinsert (*l,i,e)--Inserting a new element in the linear table L at the first position E
Instance code:
650) this.width=650; "title=" 11.jpg "src=" http://s3.51cto.com/wyfs02/M01/56/CB/wKioL1SOY2CTYwJhAAEgICcSNSA743.jpg "alt=" Wkiol1soy2ctywjhaaegiccsnsa743.jpg "/>
Two types of storage structures for linear tables
Sequential storage: A data element (such as an array) that stores linear tables sequentially in sequential storage units
Sequential storage Structure Code:
#define MAXSIZE 20
typedef int ELEMTYPE;
typedef struct
{
Elemtype Data[maxsize];
int length;
}sqlist;
The structure package requires three properties:
The starting position of the storage space, array data, where it is stored is the storage location of the linear table storage space
Maximum storage capacity for linear tables: array length maxsize
Current length of linear table: length
Address calculation method:
Assuming that Elemtype occupies a C storage unit, the relationship between the i+1 data element and the first data element in your linear table is
LOC (ai+1) =loc (AI) +c
Code snippet:
650) this.width=650; "title=" 11.jpg "src=" http://s3.51cto.com/wyfs02/M00/56/CD/wKiom1SOZ7OwIlJUAADw8l8ZUNk555.jpg "alt=" Wkiom1soz7owiljuaadw8l8zunk555.jpg "/>
Chain-Store:
Data structures and algorithms-Learning Note 3