Jump to content
  • Advertisement
Sign in to follow this  
Nidhi

Arrays...java

This topic is 4091 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys I want to perform a deletion operation on arrays but I have no clues about how should I proceed with it .If an item in the array matches with the parameter passed how am I supposed to delete it?....can anybody help me out with the algorithm for this deletion job.It's a java project. Thanks, -Nidhi

Share this post


Link to post
Share on other sites
Advertisement
There are 2 easy ways to delete an element from an array. One is to mark the element in some way so you know it has been deleted. Another is to move every element after the deletee back to occupy its space.

For the first method, remember that its fairly easy to mark something as deleted by setting it to null, provided of course that the rest of your program doesn't assume that every element in the array has to point to something valid.

Share this post


Link to post
Share on other sites
hey rip-off


ok if I use the second method..Do I have to copy the value of all the old elements ,which were before the element that I want to delete, to a new array and then move all the elements which were after the element to be deleted one step ahead.And the new array should be one less than the original array


I'm confused

Share this post


Link to post
Share on other sites
hey rip-off


ok if I use the second method..Do I have to copy the value of all the old elements ,which were before the element that I want to delete, to a new array and then move all the elements which were after the element to be deleted one step ahead.And the new array should be one less than the original array


I'm confused

Share this post


Link to post
Share on other sites
Seriously I don't know anything about vectore coz I haven't used it.I need a simple approach to this operation..Please help me out!

Share this post


Link to post
Share on other sites
Quote:
Original post by Nidhi
Seriously I don't know anything about vectore coz I haven't used it.I need a simple approach to this operation..Please help me out!


Are you doing this for use in a program, for learning about arrays or as homework?

Share this post


Link to post
Share on other sites
Well not as a homework..Actually we(me and some members of java users group on campus)are stuck on dis thing.We are working on a project that requires the use of deletion operation on arrays!

Share this post


Link to post
Share on other sites
Quote:
Original post by Nidhi
Well not as a homework..Actually we(me and some members of java users group on campus)are stuck on dis thing.We are working on a project that requires the use of deletion operation on arrays!


If the project is not about learning how to use arrays, then I would recommend using a class like ArrayList or Vector to hold your data, as these allow you to easily remove items.

If demonstrating array knowledge is part of the project then we cannot help you directly, however if you post some code we may be able to hint you to where you are going wrong.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!