I. Features of linear tables

1. Linear Structure

(1) There must be a unique "first element" and a unique "last element" in the collection ".

(2) Apart from the last element, each element has a unique successor and a unique precursor.

2. Basic operations of linear tables

(1) Use setnull (l) to set an empty table;

(2) Use length (L) to calculate the table length and the number of each element in the table;

(3) Use get (L, I) to obtain the I-th element in the table (1 = <I <= N );

(4) use prior (L, I) to obtain the precursor elements of I;

(5) use next (L, I) to obtain the successor element of I;

(6) Use locate (L, x) To return the position of the specified Element in the table;

(7) Insert new elements with insert (L, I, X;

(8) delete an existing element with Delete (L, X;

(9) use empty (l) to determine whether it is null.

3. Structural Features of linear tables

Uniformity and orderliness.

Ii. Sequence Table operations

The basic operations of a linear table are as follows:

(1) Calculate the length of the sequence table

Public int getlength () {return last + 1; // The length of the sequence table is the index of the last element of the array plus 1}

(2) Clear operation

Public void clear () {return last =-1; // clear all elements. At this time, last =-1}

(3) Determine whether the linear table is empty

public bool IsEmpty(){ if (last==-1) { return true; } else { return false; }}

(4) Determine whether the linear table is full

public bool IsFull(){ if (last==maxsize-1) { return true; } else { return false; }}

(5) additional operations

Public void append (T item) {If (isfull () {console. writeline ("list is full"); // Add an element to the end} data [++ last] = item ;}

(6) Insert operations

Public void insert (T item, int I) {// judge whether the sequence table is full if (isfull () {console. writeline ("list is full"); return;} // determines whether the inserted position is correct, // If I is less than 1, it indicates inserting before the first position. // If I is less than last + 2, it indicates inserting at the second position after the last element. If (I <1 | I> last + 2) {console. writeline ("position is error! "); Return;} // Insert the data element if (I = last + 2) {data [I-1] = item;} at the end of the sequence table ;} else // insert data elements elsewhere in the table {// move the element for (Int J = last; j> = I-1; -- J) {data [J + 1] = data [J];} // Insert a new data element to position I. Data [I-1] = item ;} // modify the table length + + last ;}

(7) Delete

Public t Delete (int I) {T TMP = default (t); // checks whether the table is empty if (isempty () {console. writeline ("list is empty"); Return TMP ;} // determine whether the deletion location is correct. // If I is smaller than 1, the elements before the first location are deleted. // If I is greater than last + 1, the elements at the second location after the last element are deleted. if (I <1 | I> last + 1) {console. writeline ("position is error! "); Return TMP;} // Delete the last element if (I = last + 1) {TMP = data [last --]; return TMP ;} else // Delete not the last element {// move the TMP = data [I-1]; for (Int J = I; j <= last; ++ J) {data [J] = data [J ++] ;}// modify the table length -- last; return TMP ;}

(8) retrieving Elements

public T GetElem(int i){ if (IsEmty()||(i<1) || (i>last + 1)) { Console.WriteLine("List is Empty or Position is error!"); return default(T); } return data[i - 1];}

(9) search by value

Public int locate (T value) {// the sequence table is empty if (isemty () {console. writeline ("list is empty! "); Return-1;} int I = 0; // cyclically processed sequence table for (I = 0; I <= last; ++ I) {// the sequence table has the element if (values. equals (data [I]) {break ;}// the sequence table does not have the element that is equal to the given value if (I> last) {return-1 ;}return I ;}

3. Linked List Operation 4. instance Drill

Linear table of data structure (1)