How To Sort List based on Dependencies in Javascript

246 Views Asked by At

Firstly, i know Topological sort :) But I couldn't solve this problem. I have a dependency based list. for Example;

ID, dependent Ids
---, ------------
[1],[]
[2],[1]
[3],[1]
[4],[1]
[5],[3]
[6],[5]
[7],[2,4,6]

I want to print list like a this:

1
-2
-3
--5
---6
-4
----7

How can I do this?

0

There are 0 best solutions below