Linear table concept: a linear table is the simplest and most commonly used data structure. A linear table is a finite sequence consisting of n (n> = 0) data elements of the same nature.
It is usually recorded as: (A1, A2, A3, A4, A5... ).
ABSTRACT Data Type of a linear table: a linear table is a flexible data structure. Its length can be increased or shortened as needed.
Public interface list <E> // linear Table Interface
{
Boolean isempty (); // determines whether the linked list is empty.
Int length (); // returns the length of the linked list.
E get (INT index); // remove the nth index Element
Void add (E element) // insert an element
Void add (INT index, e element); // insert an element at the index position
E remove (INT index); // remove the index position element and return the element
Void clear (); // clear the linear table
}
Sequential Representation and implementation of linear tables
Sequential Representation of linear tables;
Single-chain table
Public class note <E> // node class of a single-chain table
{
Public e date; // node data
Public note <E> next; // next node
}
// Single-chain table Type
Public class singlylists implements list <E>
{
Protected note <E> head; // header pointer
Public singlydomainlist () // construct an empty single-chain table
{
This. Head = NULL;
}
// Add a node
Public void add (note <E> note)
{
If (Head = NULL)
{
Head = note;
}
Else
{
Note <E> temp = head;
While (temp. Next! = NULL)
{
Temp = temp. netx;
}
Temp. Next = Note
}
}
// Omit other methods
}
Double-linked table
Public CLAS dnote <E>
{
Public e date; // node data
Public doublenote <E> Prev, next; // successor
}
Reference single-chain table