public interface Listmethod {int size ();
Determine if the linear table is an empty Boolean isempty ();
Insert element void Insert (int i, Object obj) throws Exception;
Deletes the element void Delete (int i) throws Exception;
Gets the element Object get (int i) throws Exception at the specified location; }
public class List implements listmethod{//default maximum length is 10;
public static final int defoultsize=10;
Linear table Maximum length int maxSize;
The current degree of the linear table list int length;
Object array object[] listarray;//object array public List (int length) {maxsize=length;
this.length=0;
Listarray=new Object[length];
///Determine if the linear table is null public boolean IsEmpty () {if (length==0) {true;
return false;
@Override public int size () {return length; @Override public void Delete (int i) throws Exception {//delete elements of the linear Table I (IsEmpty ()) {throw new Exception ("This table is empty and cannot be
Delete "); } if (i<0| |
I>length-1) {throw new Exception ("The table deletion is out of bounds, cannot be deleted");
for (int k=i;k<=length-1;k++) {listarray[k-1]=listarray[k];
} length--; Public Object get (int i) throws Exception {if i<0| |
I>length-1) {throw new Exception ("parameter has error");
return listarray[i]; @Override public void Insert (int i, Object obj) throws Exception {if (length==maxsize) {throw new Exception ("The location is full
, don't plug it in "); //If you insert a position smaller than 0, or the position you inserted is greater than the current maximum length if (i<0| |
i>maxsize-1) {throw new Exception ("parameter has error");
for (int k=length-1;k>=i;k--) {listarray[k+1]=listarray[k];
} listarray[i] = obj;
length++;
}}