public ArrayList<String> topSort() {
		// Empty list that will contain the sorted elements
		LinkedList<Node> sortedList = new LinkedList<Node>();
		
		// Set s of all nodes n with no incoming edges
		LinkedList<Node> s = new LinkedList<Node>();
		for (Node node : nodes) {
			if (node.incoming.isEmpty()) {
				s.add(node);
			}
		}
		
		Node n, m;
		Edge e;
		while (! s.isEmpty()) {
			n = s.remove();
			sortedList.add(n);
			
			// for each node m with an edge e from n to m do
			for (Iterator<Edge> i = n.outgoing.iterator(); i.hasNext(); ){
				e = i.next();
				m = e.to;
				
				// remove edge e from graph
				i.remove();
				m.incoming.remove(e);
				
				// if m has no other incoming edges then insert m into s
				if (m.incoming.isEmpty())
					s.add(m);
			}
		}
		
		ArrayList<String> list = new ArrayList<String>();
		for (Node node : nodes) {
			if (! node.outgoing.isEmpty()) {
				System.out.println("Error: DirectedGraph has at least one cycle");
				return list;
			}
		}
		
		for (Node node : sortedList) {
			list.add(node.getName());
		}
		return list;
	}