This week's giveaway is in the Spring forum.
We're giving away four 3 month subscriptions to Marco Behler Videos and have Marco Behler on-line!
See this thread for details.
Win a 3 month subscription to Marco Behler Videos this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Adding weight to a directed graph.  RSS feed

 
Jeremiah Parrack
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • 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
 
Stephan van Hulst
Saloon Keeper
Posts: 7487
135
  • Mark post as helpful
  • send pies
  • 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.
 
Randall Twede
Ranch Hand
Posts: 4667
8
Java Scala
  • Mark post as helpful
  • send pies
  • 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: 4667
8
Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
they do discuss it on the book site.
http://algs4.cs.princeton.edu/44sp/
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!