Win a copy of Functional Reactive Programming this week in the Other Languages forum!
    Bookmark Topic Watch Topic
  • New Topic

One more shot at removing an element from an array

 
Mike Osterhout
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Report post to moderator
I posted a similar topic and I was able to get this far



The problem is if you remove element 1 from the array it will print like this
0 this is the element
2 this is another element

This tells me that the null array is still there or in other words I am not bringing all non null elements to the front.

If this is the worst of my problems on this program I am not too worried but I would like to know why this isent working if possible.
 
Andre Brito
Ranch Hand
Posts: 95
Java Scala
  • Mark post as helpful
  • send pies
  • Report post to moderator
I didn't understand it clearly.
You want 2 arrays: one if N elements and other with N-1 elements. Is that right?

I am not bringing all non null elements to the front.

That's happening because your index is not "controlled". In other words, if you have 2 arrays:
A -> [0][1][2]
B -> [0][0][0]

and you choose to delete the element "1", you're doing like this:
A -> [0][1][2]
B -> [0][null][2]

while (I guess) you want to do this
A -> [0][1][2]
B -> [0][2][null]

. Am I right?

You must pay attention to the index (in other words, the "i"). You have to create another index to control the second array.


Just remember: your code is your "portfolio". So you should organize it better, so other programmers can understand it
 
Mike Osterhout
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Report post to moderator
That works, however I am not sure why the int i doesnt work for both indexes

 
Campbell Ritchie
Sheriff
Pie
Posts: 50258
79
  • Mark post as helpful
  • send pies
  • Report post to moderator
Mike Osterhout wrote:I posted a similar topic . . .
Don't. Read this FAQ, please. Closing thread as duplicate. Please continue discussion here.
 
    Bookmark Topic Watch Topic
  • New Topic