We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Deleting from a line
Page Index Toggle Pages: 1
Deleting from a line (Read 265 times)
Deleting from a line
Mar 2nd, 2009, 10:19pm
 
I'm trying to create a line of some shape, and when said shape is clicked on it dissapears.  This is not difficult to accomplish.  Along with this, if the shape is not the first one in the line, if it is clicked, it deletes itself as well as all the shapes to the right of it as well.

For example


_1_  _2_  _3_  _4_  _5_  _6_

if shape 6 is clicked, only number 6 dissapears, but if say shape 4 were clicked, 4, 5, and 6 would dissapear.  How would someone recommend I go about accomplishing this, I cant seem to get anything to work.
Re: Deleting from a line
Reply #1 - Mar 2nd, 2009, 11:25pm
 
Maxoe wrote on Mar 2nd, 2009, 10:19pm:
I cant seem to get anything to work.

Show us what is your best attempt, we will advice on how to improve it.
Re: Deleting from a line
Reply #2 - Mar 3rd, 2009, 12:17am
 
Look up "linked list" on wikipedia or in any computer science textbook.  Implement one of those.  When the user clicks on an element of the list, you find which one it is and then delete that element.

In C/C++ you'd have to manually delete that element and all the subsequent elements in the list, but because Java has managed memory and a garbage collector, you can just delete the one element and rely on the GC to clean up the rest of the trailing elements for you.
Page Index Toggle Pages: 1