So, I need to delete the count objects starting at the given index. I have to make sure to compress myObjects and update currentObject (Someone told me that I can't compress an array so, if you agree with that then don't worry about the compress part). I must also verify that the given index exists in myObjects and that there are count entries starting from there.

This is what I got:
NOTE: I will just show part of my program, because it's a long program but everything is working well so far...

So far, It's deleting what it has to delete but it doesn't return the currentObject appropriately

11-10-2013, 03:12 AM

jim829

Re: Deleting an object from an array (from index , count)

You are not using index properly in your deleteObjects method. First, it doesn't make sense that index should be less than count. Suppose you want to delete
3 objects starting at index location 10? What you want to insure is that the number of objects to be deleted starting at the index doesn't exceed the size of the array. As for not properly updating the currentObject, what object is that supposed to be? The first in the array? The last?

And you cannot compress arrays but you can allocate a new one of proper size and copy old to new.

Regards,
Jim

11-10-2013, 03:29 AM

maduro

Re: Deleting an object from an array (from index , count)

So, how about this:

I will show you another method similar to the deleteObjects method ( The question still the same, I just want to give you an Idea about what I want to do)

This won't work either. What you really need to do is to use a pencil and paper and draw an array with number in it. Then write down your index and count values and see how it should work. Then, once you get it working, transfer it to code. Your above algorithm only
"removes" a single value. The one starting at location count.

Regards,
Jim

11-10-2013, 04:16 AM

maduro

Re: Deleting an object from an array (from index , count)

So do you mean that if i have deleteObjects(2,9) it's only deleting at index 9?

11-10-2013, 04:27 AM

jim829

Re: Deleting an object from an array (from index , count)

Yes! You are not using index at all, only count.

Regards,
Jim

11-10-2013, 04:32 AM

maduro

Re: Deleting an object from an array (from index , count)

May I ask ..Do i need another loop?

11-10-2013, 05:13 AM

jim829

Re: Deleting an object from an array (from index , count)

Nope! Think about it this way. You have a starting index of 9 and a count of 3. Since arrays are zero based, the length of the array needs to be at least 10 + 3 or 13. Assume it is 20. Now you want to copy everything from index 9 + 3 or 12 to index 9. This will then copy 12 to 9. then 13 to 10, then 14 to 11. So you are effectively deleting items 9,10,and 11. Just make certain you don't exceed the array length. Like I said earlier, it helps to derive an algorithm first on paper.