• Post Reply Bookmark Topic Watch Topic
  • New Topic

Graph Data Structure?  RSS feed

 
Mike Lonsky
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

where the Integer key represents the vertex and the LinkedList contains all the other vertexes it points to.

How can I go about using an ArrayList to represent the vertex and the list of vertexes is points to?
 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You shouldn't care about the concrete type at all. Declare the variable like this:
Then when you add a new link, you can get the neighbor vertices like this:
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan van Hulst wrote:

Fixed.
 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hah, I keep forgetting to be lazy.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just wish they had overloaded comuteIfAbsent to not only take a Function<Key, Value> but also a Supplier<Value>. That would have allowed ArrayList::new instead of k -> new ArrayList<>().
 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I feel ya. One thing that often annoys me is when I use compute() to replace a value in the map, based solely the old value. It's really the same issue, it would be nice if they added
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!