package list.arraylist;
public abstract class ArrayListClass {
protected int length;
protected int maxSize;
protected DataElement[] list;
public ArrayListClass(){
this.maxSize=100;
this.length=0;
this.list=new DataElement[maxSize];
}
public ArrayListClass(int size) {
if(size<=0){
System.out.println("The array size must be position.Crating an array of size 100.");
this.maxSize=100;
}else
this.maxSize=size;
length=0;
this.list=new DataElement[maxSize];
}
public ArrayListClass(ArrayListClass otherList) {
this.maxSize=otherList.maxSize;
this.length=otherList.length;
this.list=new DataElement[maxSize];
for(int i=0;i<length;i++)
list[i]=otherList.list[i].getCopy();
}
public boolean isEmpty(){
return (this.length==0);
}
public boolean isFull(){
return (this.length==this.maxSize);
}
public int listSize(){
return this.length;
}
public int maxListSize(){
return this.maxSize;
}
public void print(){
for(int i=0;i<length;i++)
System.out.print(list[i]+" ");
System.out.println();
}
public boolean isItemAtEqual(int location,DataElement item){
return (list[location].equals(item));
}
public void insertAt(int location,DataElement insertItem){
if(location<0||location>=maxSize)
System.out.println("The position of the item to be inserted is out of range.");
else
if(length>=maxSize)
System.out.println("Cannot insert in a full list.");
else{
for(int i=length;i>location;i--)
list[i]=list[i-1];
list[location]=insertItem.getCopy();
length++;
}
}
public void insertEnd(DataElement insertItem){
if(length>=maxSize)
System.out.println("Cannot inset in a full list.");
else{
list[length]=insertItem.getCopy();
length++;
}
}
public void removeAt(int location){
if(location<0||location>=length)
System.out.println("The location of the item to be removed is out of range.");
else{
for(int i=location;i<length-1;i++){
list[i]=list[i+1];
}
list[length-1]=null;
length--;
}
}
public DataElement retrieveAt(int location){
if(location<0||location>=length){
System.out.println("The location of the item to be retrieved is out of range.");
return null;
}else{
return list[location].getCopy();
}
}
public void replaceAt(int location,DataElement repItem){
if(location<0||location>=length){
System.out.println("The location of the item to be replaced is out of range.");
}else{
list[location].makeCopy(repItem);
}
}
public void clearList(){
for(int i=0;i<length;i++)
list[i]=null;
length=0;
System.gc();
}
public abstract int seqSearch(DataElement searchItem);
public abstract void insert(DataElement insertItem);
public abstract void remove(DataElement removeItem);
public void copyList(ArrayListClass otherList){
if(this!=otherList){
for(int i=0;i<length;i++)
list[i]=null;
System.gc();
maxSize=otherList.maxSize;
length=otherList.length;
list=new DataElement[maxSize];
for(int j=0;j<length;j++)
list[j]=otherList.list[j].getCopy();
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
DataStructTest.rar (29个子文件)
DataStructTest
bin
list
linkedlist
UnorderedLinkedList.class 2KB
OrderedLinkedList.class 2KB
LinkedListClass$LinkedListNode.class 586B
DataElement.class 503B
LinkedListClass.class 3KB
arraylist
polynomial
Polynomial.class 2KB
test.class 2KB
Calculate.class 3KB
ArrayTest.class 569B
DataElement.class 497B
UnorderedArrayList.class 2KB
ArrayListClass.class 4KB
moneyGame
test.class 1KB
Player.class 1023B
CoinStrip.class 1KB
test
testY.class 909B
testX.class 535B
test.class 524B
.settings
org.eclipse.jdt.core.prefs 598B
src
list
linkedlist
LinkedListClass.java 2KB
UnorderedLinkedList.java 1KB
DataElement.java 287B
OrderedLinkedList.java 2KB
arraylist
DataElement.java 286B
ArrayTest.java 225B
UnorderedArrayList.java 1KB
ArrayListClass.java 3KB
.project 390B
.classpath 299B
共 29 条
- 1
资源评论
Emmitte
- 粉丝: 122
- 资源: 70
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功