顺序表的类定义(Java语言描述)

Written by Bruth_Lee in Southwest University of Science And Technology.

Maybe you are so worried about DataStructure in Java as you are a primer java, but you don't worried, I will write a lot of blog about DataStructrue in the next.

List ---a interface

package Second_chapter;

public interface List {
	public void clear();//Initialization
	public Object gete(int i);//Return the i element
	public int leng();//Seek length
	public int loct(Object el);//Find, If el has been found, return the sequence of element,else return null;
	public boolean inst(int loc, Object el);//Insert el into loc;
	public Object dele(int loct);//Delete the element in the loc position;
	public boolean full();//Judge whether the sequence_list is full;
	public boolean empt();//Judge whether the sequence_list is empt;
}
SqList---a class

package Second_chapter;

public class SqList implements List{
	final int deflen = 10;
	Object[] elem;
	int curlen;//The length of Sequence_List currently;
	int maxlen;//Maximum length of Sequence_list;
	public SqList() {
		curlen = 0;
		maxlen = deflen;
		elem = new Object[maxlen];
	}
	public SqList(int maxzs) {
		curlen = 0;
		maxlen = maxzs;
		elem = new Object[maxlen];
	}
	public SqList(Object[] a, int maxzs) {
		int n = a.length;
		curlen = n;
		maxlen = (maxzs>n)?maxzs:n;//return the bigger number between maxzs and n;
		elem = new Object[maxlen];
		for(int i = 0; i=1 && i<=curlen) return i-1;
		else return null;
	}

	@Override
	public int leng() {
		// TODO Auto-generated method stub
		return curlen;
	};

	@Override
	public int loct(Object el) {
		// TODO Auto-generated method stub
		int i=0;
		while(icurlen+1 || curlen == maxlen)
		return false;
		else {
			curlen++;
			for(i=curlen-1;i>=loc;i--) {
				elem[i]=elem[i-1];
			}
			elem[loc-1]=el;
			return true;
		}
	}

	@Override
	public Object dele(int loct) {
		// TODO Auto-generated method stub
		int i;
		Object el;
		if(loct<1 || loct>curlen ) return null;
		else {
			el=elem[loct-1];
			for(i=loct;i



你可能感兴趣的:(算法编程题合集)