This problem has been bothering me for a long time recently. I have the following json data
[
{"prev_node": "0000000000000005","next_node": "0000000000000006"},
{"prev_node": "0000000000000006","next_node": "0000000000000007"},
{"prev_node": "0000000000000006","next_node": "0000000000000008"},
{"prev_node": "0000000000000008","next_node": "0000000000000012"},
{"prev_node": "0000000000000009","next_node": "0000000000000010"},
{"prev_node": "0000000000000010","next_node": "0000000000000011"},
{"prev_node": "0000000000000014","next_node": "0000000000000015"},
{"prev_node": "0000000000000015","next_node": "0000000000000016"},
{"prev_node": "0000000000000016","next_node": "0000000000000017"},
{"prev_node": "0000000000000018","next_node": "0000000000000019"},
{"prev_node": "0000000000000020","next_node": "0000000000000021"},
{"prev_node": "0000000000000019","next_node": "0000000000000020"},
{"prev_node": "0000000000000012","next_node": "0000000000000022"},
{"prev_node": "0000000000000022","next_node": "0000000000000023"},
{"prev_node": "0000000000000023","next_node": "0000000000000009"},
{"prev_node": "0000000000000011","next_node": "0000000000000024"},
{"prev_node": "0000000000000024","next_node": "0000000000000014"},
{"prev_node": "0000000000000017","next_node": "0000000000000025"},
{"prev_node": "0000000000000025","next_node": "0000000000000018"},
{"prev_node": "0000000000000007","next_node": "0000000000000021"},
{"prev_node": null,"next_node": "0000000000000005"},
{"prev_node": "0000000000000021","next_node": null}
]
Among them, prev_node represents the previous node, and next_node is the next node. If prev_node is Null, it represents the current node. Next_node is null, which represents the last node. According to the data, the following flow chart is obtained
Find the nodes of the current deepest process and how many branches there are
Note: Nodes can only go down
Um, isn’t it just a deep search
This structure is like a directed graph in data structure