Computer Science Canada Deleting Flexible arrays |
Author: | shoobyman [ Wed Apr 18, 2007 6:15 pm ] | ||
Post subject: | Deleting Flexible arrays | ||
I have this piece of code, and as you can see (where it says deleting flexible arrays), it only deletes the sparkles one at a time. This works fine if i only have 1 sparkle, but i have hundreds. Does anyone know a way to delete more than one part of a flexible array at once (within the same loop iteration)? this is the code
|
Author: | CodeMonkey2000 [ Thu Apr 19, 2007 5:07 pm ] | ||||
Post subject: | Re: Deleting Flexible arrays | ||||
First store all the array elements that need to be deleted inside a flexible array.
Then store all the elements that need to be deleted inside useless (eg. if spark(4) need to be deleted,then increase the size of useless and store 4 inside useless(1), and if spark (50) needs to be deleted, then increase the size of useless and store 50 inside useless(2) etc.). Then you use it in a for loop like so:
|
Author: | Cervantes [ Thu Apr 19, 2007 6:08 pm ] |
Post subject: | RE:Deleting Flexible arrays |
Lots of material can be found here. It looks like codemonkey2000 has a good idea. It's discussed in the above linked article too. There maybe be better ways to do it, but this is probably the simplest that works as you want it to. Using a linked list to store the indeces of the elements you want to remove would be better, since it takes far less work to add an element to a linked list than it does to a flexible array. However, this will be more work for you, since linked lists are not built into Turing. |