@Override
public void insertItem(Comparable item, int position) {
//throw new UnsupportedOperationException("Not supported yet.");
if (!(this.full())){
throw new SimpleListException("Full list");
}
else{
for(int i = 0; i < freeListArray.length; i++){ //find first free location
if(freeListArray[i] != NULL){
break;
}
}
linksArray[i] = freeListArray[i]; //put location in links
dataArray[linksArray[i]] = item; //put item into data
temp = linksArray[i];
linksArray[dataArray[temp]] = -1; //show where end of array is
}
}
Constructor is as follows:
public SimpleComparableList(){
this.capacity = DEFAULT_CAPACITY;
this.currentPosition = 1;
this.dataArray = new String[capacity];
this.linksArray = new int[capacity];
this.freeListArray = new int[capacity];
}
public SimpleComparableList(int capacity){
// Constructs and initializes a list that is empty. Current list size is
// zero and current position is set to one.
this.capacity = capacity;
this.currentPosition = 1;
this.dataArray = new String[capacity];
this.linksArray = new int[capacity];
this.freeListArray = new int[capacity];
}