added iterative way to do topological sorting