Home  >  Article  >  Java  >  Example of Java linear table interface

Example of Java linear table interface

黄舟
黄舟Original
2017-09-28 09:53:571210browse

这篇文章主要介绍了java 线性表接口的实现实例详解的相关资料,希望通过本能帮助到大家,需要的朋友可以参考下

java 线性表接口的实例详解

前言:

线性表是其组成元素间具有线性关系的一种线性结构,对线性表的基本操作主要有插入、删除、查找、替换等,这些操作可以在线性表的任何位置进行。线性表可以采用顺序存储结构和链式存储结构表示。

本接口的类属于dataStructure包的linearList子包。线性表接口LList声明如下,描述线性表的取值、置值、插入、删除等基本操作。


package dataStructure.linearList; 
  
public interface LList<E> 
{ 
  boolean isEmpty();         //判断线性表是否为空,若空返回ture 
  int length();            //返回线性表长度 
  E get(int index);          //返回序号为index的对象,index初值为0 
  E set(int index,E element);     //设置序号为index对象为element,返回原对象 
  boolean add(int index,E element);  //插入element对象,插入后对象序号为index 
  boolean add(E element);       //插入element对象,插入位置没有约定 
  E remove(int index);        //移去序号为index的对象,放回被移去对象 
  void clear();            //清空线性表 
}

顺序存储和链式存储的线性表类(顺序表类和链表类)实现LList接口,提供LList接口中方法的具体实现。例如:


public class SeqList<E> implements LList<E>       //顺序表类 
public class SinglyLinkedList<E> implements LList<E>  //单链表类

LList接口中的方法在顺序表类和链表类中表现出多态性。

The above is the detailed content of Example of Java linear table interface. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn