Update: If you want to represent the graph of this list:
Making some quite plausible assumptions on what exactly this list is supposed to represent, you might first draw a circle and name it 1 (write 1 in the middle of the circle) to represent the first node. This first node has three successors, 2, 5 and 7. So you just draw 3 other circles, with a 2, 5 and 7 in the middle, and draw an arrow from node 1 to nodes 2, 5 and 7. Then, from node 2 you draw two outbound arrows to the two new nodes, 6 and 8. Then you create node 3, and draw two arrows from it to existing nodes 1 and 2.1 2 1 5 1 7 2 6 2 8 3 1 3 2
This is just one of the classical ways to represent graphs in a computer, there are some others.
In Perl, this graph could be implemented as an array of two-element arrays (([1, 2], [1, 5], [1, 7], ... [3, 2]), but, depending on what this graph is going to be used for, that might not be a very practical implementation to use. It could also be implemented as a hash of arrays: (1 => [2, 5, 7], 2 => [6, 8], 3 => [1, 2]), which might be more practical to use for some types of processing. For other types of calculations, you might want to reverse the representation and use the successor nodes as keys and predecessors (or lists of predecessors) as values or lists of values. It really depends on the data structure and the processing that needs to be done on it.
In reply to Re^2: Data type name required [not Perl exclusive question]
by Laurent_R
in thread Data type name required [not Perl exclusive question]
by baxy77bax
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |