At 3/9/06 08:39 PM, whatthedeuce wrote::
We would really have to know what was in "array", and what the value of "end" and "n" are to help you.
im talking about a array list, you know, an unlimited array so to speak, i understand perfectly how it works but i dont understant the % function, i havent seen it in my class (college class of course) i dont need an explanation bout what a list is, only need to know the role of the % carachter in the instruction, im not that familiar with java.
heres the code anyway
public class pArrayList{
protected Object[] array;
protected int start,end,number;
public pArrayList(int maxsize){
array = new Object[maxsize];
start = end = number = 0;
}
public boolean isEmpty(){
return number == 0;
}
public boolean isFull(){
return number >= array.length;
}
public int size(){
return number;
}
public void insert(Object o){
if(number < array.length){
array[start = (++start % array.length)] = o;
number++;
}
}
public void insertEnd(Object o){
if(number < array.length){
array[end] = o;
end = (--end + array.length) % array.length;
number++;
}
}
public Object remove(){
if(isEmpty())
return null;
number--;
int i = start;
start = (--start + array.length) % array.length;
return array[i];
}
public Object removeEnd(){
if(isEmpty())
return null;
number--;
return array[end = (++end % array.length)];
}
public Object peek(int n){
if(n >= number)
return null;
return array[(end + 1 + n) % array.length];
}
}