Forums Register Login

Graph Data Structure?

+Pie Number of slices to send: Send

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?
+Pie Number of slices to send: Send
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:
+Pie Number of slices to send: Send
 

Stephan van Hulst wrote:


Fixed.
+Pie Number of slices to send: Send
Hah, I keep forgetting to be lazy.
+Pie Number of slices to send: Send
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<>().
+Pie Number of slices to send: Send
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
It's hard to fight evil. The little things, like a nice sandwich, really helps. Right tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 463 times.
Similar Threads
Arraylists of arraylist as a representation of relationships
Dijkstra's algorithm
Writing a graph class
"Position" Concept as it applies to Data Structures
I need graph representation API
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 04:41:42.