Data structure (Yan Weimin and Wu Weimin)-Reading Notes-2. Linear table and its basic operations and sequential storage structure, Wu Weimin-2
Chapter 2 linear table
2.1 linear table and its basic operations
2.2 sequential storage structure of linear tables
2.3 chain storage structure of linear tables
1. Linear table: A finite sequence of n data elements.
Direct precursor element and direct successor element. When n = 0, it is called an empty table.
A Data Element can contain several data items. In this case, the data element is often calledRecordA linear table containing a large number of records, also knownFile.
2. Basic operations
InitList (& L) initialization operation sets an empty linear table L
ListLength (L) Evaluate the length function value as the number of data elements in the linear table L
GetElem (L, I, & e) returns the I-th Data Element in L to e when the element function 1 <= I <= Length (L) is used. Otherwise, NULL is the NULL element. I is called the order of the data element in L.
PriorElem (L, cur_e, & pre_e) is a data element in L. If its order is greater than 1, the function value is cur_e pre_e. Otherwise, it is NULL.
NextElem (L, cur_e, & next_e) calculates the successor element. If the rank of the successor element cur_e is smaller than the table length, the function value is the successor next_e of elm. Otherwise, the value is NULL.
LocateElem (L, e, compare () positioning function assigned value e. If e is not in the table, 0 is returned; otherwise, the bid of e when it first appears in the table is returned.
Before ListInsert (& L, I, e), insert new element B before element I. The value range of I is: 1 <= I <= n + 1; I = n + 1 indicates that the table is inserted at the end, and n indicates the table length.
The ListDelete (& L, I, e) delete operation deletes the I-th element in the linear table L, 1 <= I <= n, and returns its value with e.
ListEmpty (L) specifies the empty table function. If L is an empty table, a Boolean value "true" is returned. Otherwise, a Boolean value "false" is returned"
The ClearList (& L) Table is left empty.
3. Sequential storage structure of linear tables
Sequential storage structure of linear tablesIt refers to storing the data elements of a linear table in sequence with a set of sequential storage units.
Loc (ai) = Loc (a1) + (I-1) * k
4. insert and delete linear tables
Sequential storage structure for Dynamic Allocation of linear tables
Add a space for storing LISTINCREMENT data elements to the sequence table.
Idea of inserting algorithms:
> If the Insertion Location is unreasonable, an exception is thrown;
> If the linear table length is greater than or equal to the array length, an exception is thrown or the capacity is dynamically increased;
> Traverse from the last element to the position I, and move them both backward;
> Fill in position I for the element to be inserted;
> The table length is increased by 1.
Algorithm:
Idea of deleting an algorithm:
> If the deletion location is unreasonable, an exception is thrown;
> Retrieve and delete elements;
> Traverse from the position of the deleted element to the position of the last element and move them both forward to one position;
> The table length is reduced by 1.
Algorithm:
The time complexity of inserting and deleting algorithms is O (n)
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.