• 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

Adding weight to a directed graph.

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello!
I have been trying for hours to add weight to my graph only to really mess things up (luckily I back things up). Any advice to add weights to my graph would be amazing. This program prints out an adjacency list  I want it to print out the adjacency list with the weight next to the node. I would post what I have worked on but I deleted it and I am starting back from the start.





and my main is
 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your names and data structures are very confusing to me. Why is an array of vertices called arrayOfLists, and not simply vertices? Why does a node have a vertex index, and a next node? Why does a vertex have a node, and why is it not the same thing as a node? Why are you using arrays and not data structures that grow dynamically and can easily index their contents, such as a Map?

If I made a graph data structure, I would let a node/vertex keep track of their name/key, neighbors and maybe an associated value (which in this case you can use for weights). A graph keeps track of all the nodes by mapping them against their keys. You can use generic type parameters for the node's key and value types.
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am reading a book right now that tells you exactly how to do it. unfortunately I don't have it with me right now. you might be able to access it at algs4.cs.princeton.edu
 
Randall Twede
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
they do discuss it on the book site.
http://algs4.cs.princeton.edu/44sp/
reply
    Bookmark Topic Watch Topic
  • New Topic