int inseririnsert(int[] data, int size, int newData){
if( ??? )
data[size++] = newData;
return size;
}
a)!isFull(data, size+1)
b)isFull(data, size+1)
c)!isFull(data, size)
d)isFull(data, size)
e)!isFull(data, size-1)
Para testat o código acima eu uso esse código:
void setup(){
int MAX_SIZE = 4;
int[] numbers = new int[MAX_SIZE];
int howMany = 0;
howMany = insert(numbers,howMany,34);
howMany = insert(numbers,howMany,99);
howMany = insert(numbers,howMany,14);
howMany = insert(numbers,howMany,22);
// howMany = insert(numbers,howMany,50);
int newSize = insert(numbers, howMany, 57);
if( newSize == howMany )
println("Insert failed!! " + newSize);
howMany = newSize;
delete(numbers, newSize);
// howMany = insert(numbers,howMany,50);
printAll(numbers,howMany);
println (isFull (numbers,howMany));
}
void printAll(int[] data, int size){
for(int i=0; i<size; i++)
print(data[i]+" ");
println();
}
int insert(int[] data, int size, int newData){
if( !isFull(data, size) )
data[size++] = newData;
return size;
}
boolean isFull(int[] data, int size){
return size == data.length;
}
int delete(int[] data, int size){
if(size>0){
for( int i=1; i<size; i++ )
data[i-1]=data[i];
size--;
}//if
return size;
}