• Post Reply Bookmark Topic Watch Topic
  • New Topic

incrementally adding to array  RSS feed

 
ernest mcdermott
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi everyone,
im currently working on minimal spanning tree style program. Im having a small but significant problem. Whenever my program selects a minimum edge, i add this edge to an array so that it cant be chosen again, however when i loop through on the second iteration, the program replaces this with the new minimum edge and so next time the minimum edge it finds is the same as the first time. Basically:
florida -- 312 -- orlando
texas -- 345 -- milwaukee
florida -- 312 -- orlando
texas -- 345 -- milwaukee etc etc etc.

Can anyone tell me how i can continually add the minimum edges to an array so that they all stay in it and stop the cycle occurring
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you have all elements in a list and keep removing them as you go? if you want to keep a list of removed items you could put them in a removedItems list.
 
ernest mcdermott
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks steve,
i think it should work. im not great with lists though, any recommendations on how to attempt it??
Many thanks
ernest
 
Murad Iqbal
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a Vector or even an ArrayList would do. Use the remove method if you use Vector to get the Object. Place it at in a new place. This way you can be sure it wont appear in the next iteration. Hope this helps.
 
ernest mcdermott
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Murad, iv been working on the arrayList for w while now with no real luck, might try vector now. Also though, is it possible to convert arrays i already have into lists or vectors, without the need to go back and change my arrays at the beginning???
Many thanks again
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!