public class SeqList{ final int defaultSize=10; int size; int maxSize; Object listArray[]; public SeqList(){ initiate(defaultSize); } public SeqList(int size){ initiate(size); } public void initiate(int sz){ //初始化顺序链表 maxSize=sz; size=0; listArray=new Object[sz]; } public void insert(int i,Object obj) throws Exception{ //在顺序链表指定位置i插入元素obj if(size==maxSize){ throw new Exception("顺序表已满,没法插入!!"); } if(i<0||i>size){ throw new Exception("参数错误!!"); } for(int j = size; j > i; j--){ listArray[j] = listArray[j-1]; } listArray[i]=obj; size++; } public Object delete(int i) throws Exception{ //删除顺序链表指定位置i的元素 if(i<0||i>size-1){ throw new Exception("参数错误!!"); } if(size==0){ throw new Exception("顺序表已空没法删除!!"); } for(int j=i;j<size-1;j++){ listArray[j]=listArray[j+1]; } size--; return listArray[i]; } public Object getData(int i) throws Exception{ //获得顺序链表指定位置i的元素 if(i<0||i>size-1){ throw new Exception("参数错误!!"); } return listArray[i]; } public int size(){ //获得顺序链表的容量大小 return size; } public boolean isEmpty(){ //判断顺序链表是否为空 return size==0; } public void MoreDataDelete(SeqList L,Object x) throws Exception{ //删除顺序链表L的所有x元素 int i; //int tag=0; for(i=0;i<size;i++){ if(x.equals(L.getData(i))){ L.delete(i); i--; // tag=1; } } //return tag; } }