Use of linear tables

Source: Internet
Author: User
Tags abstract data structures empty

The logical definition of linear table

A linear table (Linear list) is a finite sequence composed of n (n≥0) data elements (nodes) A1,a2,...,an.

The number N of the ① data element is defined as the length of the table (n=0 is called an empty table).

② The Non-empty linear table (n>0) as: (A1,a2,...,an)

③ data Element ai (1≤i≤n) is just an abstract symbol, and its specific meaning can be different in different situations.

The logical structure characteristics of linear table

For a non-empty linear table:

① has and only one beginning node A1, there is no direct forward, there is only one direct successor A2;

② has and only one end node an, there is no direct successor, there is and only a direct forward an-1;

③ the rest of the internal node AI (2≤i≤n-1) has and only one direct forward ai-1 and one ai+1.

Adt

A ADT is defined only by the data types that are saved and the operations that may be performed on this data type. Developers can only access ADT properties through ADT Operations, and they do not know how the various operations within the data type are implemented.

In Java, we often use an interface to give a set of operations without disclosing the details of the implementation of these operations. Remember that an interface defines a set of methods that a Java class must implement to satisfy its mandatory conditions or to implement an instance of this interface.

Linear tables, stacks, and queues

When we talk about ADT, we often speak of linear tables, stacks, and queues. We will not discuss the details of these data structures, but we will discuss why they are called ADT.

A linear table is a collection of finite elements whose elements are arranged in a linear manner and provide direct access to its elements. A stack is an ordered linear table of LIFO (LIFO) in which elements are added from the stack header and removed from the stack header. A queue is a first-in, first-out, ordered linear table in which elements are added from the end of the queue and removed from the queue header.

Linear tables, stacks, and the internal structure of queues can be implemented in many ways. For example, we can use an ordered array or a linked list to implement each structure. The key point is that no matter how you implement its internal structure, its external interface is always the same. This allows you to modify or upgrade the underlying implementation without having to change the public interface section.

Java Collection Schema

The Java 2 Software Development Kit (SDK) provides new classes to support most commonly used ADT. These classes are called Java collection classes (similar to the collection classes in MFC), and they work together to form a Java collection schema. This collection architecture provides a set of interfaces and classes that represent data as so-called collection abstract data.

The Java.util.Collection interface is used to represent arbitrary groups of objects, that is, elements. This interface provides basic operations such as adding, deleting, and querying. The collection interface also provides a iterator method. The iterator method returns an instance of the Java.util.Iterator interface. The iterator interface also provides the Hasnext, next, and remove methods. Using the method provided by the iterator interface, you can iterate through an instance of a collection object and safely delete the elements represented by the iterator (cursor).

Java.util.AbstractCollection is the basis for all collection schema classes. The Abstractcollection class provides implementations of all methods except the iterator and size methods in the Java.util.Collection interface. The two exception methods are implemented by all inherited java.util.AbstractCollection subclasses.

A class that implements an interface must provide an implementation of all interface methods. Because some of the interface methods in the collection schema are optional, there must be a way to notify the caller that some method is not implemented. When an optional method is implemented and the method is not implemented, a Unsupportedoperationexception exception is thrown. The Unsupportedoperationexception class inherits the RuntimeException class. This allows the caller to invoke all the collection operations without having to place each invocation in a Try-catch pair.

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.