Data Structure and algorithm linear table

Source: Internet
Author: User

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

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.