首页 新闻 赞助 找找看

数据结构线性表代码如何实现?

0
[待解决问题]

package SeqInterFace;

//线性表操作可能出现的4种异常的定义;

class flowOrErrorException extends Exception {

public flowOrErrorException(int i) {

if (i == 1) {

System.out.println("插入或删除位置非法\n");

System.exit(1);

}

if (i == 2) {

System.out.println("表空间溢出,退出运行\n");

System.exit(1);

}

if (i == 3) {

System.out.println("线性表为空,退出运行\n");

System.exit(1);

}

if (i == 4) {

System.out.println("查找位置非法\n");

System.exit(1);

}

}

}

 

public interface SeqInterface {

/* 顺序表的建立: 从键盘读入n个数据作为线形表的内容*/

public void CreateList(int n);

 

/* 顺序表的打印: */

public void PrintList() ;

 

// 求表长度

public int getLength();

 

// 求表的第一个元素

public String first() ;

 

// 求表的最后一个元素

public String lasty() ;

 

/* 顺序表的查找:返回打印元素的所在位置 */

public void LocateList(String x) ;

 

// 求某元素的位置,没找到返回-1

public int index(String a);

 

// 查找前驱1: 按序号查询第i个元素前驱

public String prev(int i) throws flowOrErrorException ;

 

// 查找前驱2:按元素查询元素前驱

public String prev(String a) throws flowOrErrorException;

 

// 查找后继1:按序号查询第i个元素后继

public String next(int i) throws flowOrErrorException ;

 

// 查找后继2:按元素查询元素后继

public String next(String a) throws flowOrErrorException ;

 

/* 顺序表的插入1:插至表尾 */

public void InsertList(String x) throws flowOrErrorException ;

 

/* 顺序表的插入2:将新结点x插入L所指的顺序表的第i个结点的位置上 */

public void InsertList(String x, int i) throws flowOrErrorException ;

 

/* 顺序表的删除1:从L所指的顺序表中删除第i个结点 */

public void DeleteList(int i) throws flowOrErrorException ;

 

/* 顺序表的删除2:从L删除节点x */

public void DeleteList(String x) throws flowOrErrorException ;

}

深海蓝月的主页 深海蓝月 | 菜鸟二级 | 园豆:202
提问于:2018-06-27 22:16
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册