Say we have:
Code:
thing thingArray[];
void setup()
{
size(100,100);
thingArray=new thing[200];
for(int i=0;i<thingArray.length;i++)
thingArray[i]=new thing();
}
void draw()
{
}
class thing
{
float data;
thing()
{}
thing(thing t)
{
this.data=t.data;
}
}
thing[] append(thing t[],thing newThing)
{
thing temp[]=new thing[t.length+1];
System.arraycopy(t,0,temp,0,t.length);
temp[t.length]=new thing(newThing);
return temp;
}
The append function is meant to demonstrate how I usually add something to the end of an array, regardless of object. I usually just write one of these handy append functions for every object I make that needs this sort of thing.
Now my question is.. is there an equally smart way to write a function that removes a particular object from an array, then reduce the array size by one? Say something like:
thingArray=remove(thingArray,8);
That function should remove the eigth element (thingArray[7]) from the array.
I can think of a few ways... but they are all horrible and cumbersome.. including cutting the array in half.. then reattatching it. Ew.
Anyone have a better solution?