• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

incrementally adding to array

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
To do a great right, do a little wrong - shakepeare. twisted little ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic