javascript - Flow chart to obtain depth, please help with algorithm experts
仅有的幸福
仅有的幸福 2017-05-19 10:48:24
0
2
1114

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

仅有的幸福
仅有的幸福

reply all(2)
过去多啦不再A梦

Um, isn’t it just a deep search

滿天的星座

This structure is like a directed graph in data structure

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template