implemented topographical sorting algorithm