C # data structure and algorithm series (ii) sequence table of linear tables

Source: Internet
Author: User

Linear table (List)
A linear table is the most basic, simple, and commonly used data structure. The relationship between data elements in a linear table is one-to-one,
That is, except the first and last data elements, other data elements are connected at the beginning and end. The logical structure of a linear table is simple and convenient.
Implementation and operations. Therefore, the linear table data structure is widely used in practical applications. Linear table is a common
This chapter introduces the linear table and its sequential storage, and provides a detailed design description of the stack and queue and Their sequential implementations.
In practice, linear tables are used in the form of special linear tables such as stacks, queues, strings, and arrays. Because of these special lines
Performance tables have their own characteristics. Therefore, to master the features of these special linear tables, data operation reliability and operational efficiency are both improved.
Is crucial.

A linear table is a linear structure. It is a finite sequence Containing n or greater than 0 knots. For the knots, there is only one starting knot.
There is no forward node, but there is a successor node. There is only one terminal node, but there is a forward node.
There is only one precursor and one successor node. Generally, a linear table can be expressed as a linear sequence: k1, k2 ,..., Kn, where k1 is
Start Node. kn is the terminal node. N is the length of a linear table. When n = 0, a linear table is an empty table. We usually see a lot
An instance of a linear table. For example, 1-100 is a linear table, which is expressed as (, 3,...,). An array or a database table is also
Linear table. Note: A linear table is an ordered (ordered) set of data elements.

The basic features of a linear structure are:
1. A unique "first element" must exist in the collection ";
2. A unique "last element" must exist in the collection ";
3. Except for the last element, each element has a unique successor (post );
4. Apart from the first element, each element has a unique precursor (front part ).
 
The linear table interface is as follows:

Basic operations on Linear tables
1. Length: GetLength ()
Initial Condition: a linear table exists;
Operation Result: returns the number of all data elements in a linear table.

2. Clear ()
Initial Condition: a linear table has data elements;
Operation Result: all data elements are cleared from the linear table. The linear table is empty.

3. Determine whether the linear table is empty: IsEmpty ()
Initial Condition: a linear table exists;
Operation Result: If the linear table is empty, true is returned. Otherwise, false is returned.

4. Additional operation: Append (T item)
Initial Condition: The linear table exists and is not full;
Operation Result: add the new element with the value of item to the end of the table.

5. Insert operation: Insert (T item, int I)
Initial Condition: a linear table exists and the inserted position is correct () (1 ≤ I ≤ n + 1, n indicates the table length before insertion ).

6. Delete operation: Delete (int I)
Initial Condition: The linear table exists and the linear table is not empty.

7. element: GetElem (int I)
Initial Condition: The linear table exists and the linear table is not empty.

8. Search by value: Locate (T value)
Initial Condition: The linear table exists and the linear table is not empty.

A linear table has the following structural characteristics: (if you want to take this course, pay attention to the following two points)
1. Uniformity: although the data elements of different data tables can be various, the data elements of the same linear table must have the same number length.
2. ordering: the position of each data element in a linear table depends only on their order and the relative position before the data element is linear, that is, there is a unique "first" and "last" Data
Except for the first and last elements, only one data element exists before and after each element ).


In order to store data elements in a linear table, two methods are available: sequential Storage Structure and chained storage structure. The chain storage structure will be introduced in the linear linked list of this website. This chapter mainly introduces the usage
Groups are used to store data elements in a linear table in sequence and their applications. In addition, stacks, queues, and strings are special cases of linear tables, also known as restricted linear structures.

Sequence Table

A sequence table is a linear table stored in the computer memory as an array. It stores the linear structure of data elements in sequence with a set of sequential storage units.
Linear tables are stored in sequence. A sequence table stores the nodes in the Table in computer memory and connects them to a group of addresses.
. Store elements in a table to a group of continuous storage units one by one. This storage structure is a sequential structure. Adopt order
The linear table of the storage structure is abbreviated as "sequence table ". Sequence tables store the following features: as long as the starting position is determined, the addresses of any element in the table are connected.
Get through the following formula: LOC (ai) = LOC (a1) + (I-1) * L 1 ≤ I ≤ n where, L is the length of the element occupies the storage unit.

For example, each node in the sequence table occupies len memory units, and location (ki) is used to represent the address of the 1st unit of memory space occupied by the I node ki in the sequence table.
The relationship is as follows:
Location (ki + 1) = location (ki) + len
Location (ki) = location (k1) + (I-1) len
The storage structure must reflect the logical structure of the data. In the storage structure of the sequence table, nodes adjacent to physical addresses in the memory must have the logical relationship in the sequence table.

Construct a linear table class:
Public InterfaceIListDS<T> 
{
IntGetLength ();
VoidClear ();
BoolIsEmpty ();
BoolIsFull ();
VoidAppend (T item );
VoidInsert (T item,IntI );
T Delete (IntI );
T GetElem (IntI );
StringLocate (T value );

}

Public ClassTList<T>: IListDS<T>
{
PrivateT [] _ list;
Private Int_ Len;
Private Int_ LastOne;

PublicTThis[IntLength]
{
Get{Return_ List [length];}
Set{_ List [length]=Value ;}
}

Public

Related Article

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.