Mercurial > public > think_complexity
comparison Graph.py @ 22:84e183b40c63
Added exercises 1 and 2 from chapter 4.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Mon, 31 Dec 2012 18:58:21 -0600 |
parents | 1defe6fcf9d3 |
children | 10db8c3a6b83 |
comparison
equal
deleted
inserted
replaced
21:55880b29b4d4 | 22:84e183b40c63 |
---|---|
217 visited.add(v) | 217 visited.add(v) |
218 if visit_func: | 218 if visit_func: |
219 visit_func(v) | 219 visit_func(v) |
220 | 220 |
221 # Add the adjacent neigbors to the node to the queue | 221 # Add the adjacent neigbors to the node to the queue |
222 queue.extend(self.out_vertices(v)) | 222 queue.extend(c for c in self.out_vertices(v) if c not in visited) |
223 | 223 |
224 return visited | 224 return visited |
225 | 225 |
226 def is_connected(self): | 226 def is_connected(self): |
227 """Returns True if the graph is connected (there is a path from every | 227 """Returns True if the graph is connected (there is a path from every |