From 1f45095f6030b159f4f08e75934c76e5572356b9 Mon Sep 17 00:00:00 2001 From: Donne Martin Date: Sun, 23 Aug 2015 08:08:46 -0400 Subject: [PATCH] Added three state variable visit_state which will be useful for more advanced challenges such as topological sort. --- graphs_trees/graph/graph.py | 9 ++++++++- graphs_trees/graph/graph_solution.ipynb | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/graphs_trees/graph/graph.py b/graphs_trees/graph/graph.py index 5379682..7f8351e 100644 --- a/graphs_trees/graph/graph.py +++ b/graphs_trees/graph/graph.py @@ -1,11 +1,18 @@ from collections import OrderedDict +from enum import Enum # Python 2 users: Run pip install enum34 + + +class State(Enum): + unvisited = 1 + visited = 2 + visiting = 3 class Node: def __init__(self, id): self.id = id - self.visited = False + self.visit_state = State.unvisited self.adjacent = OrderedDict() # key = node, val = weight def __str__(self): diff --git a/graphs_trees/graph/graph_solution.ipynb b/graphs_trees/graph/graph_solution.ipynb index 22a2a5a..c0d8bee 100644 --- a/graphs_trees/graph/graph_solution.ipynb +++ b/graphs_trees/graph/graph_solution.ipynb @@ -135,13 +135,20 @@ "source": [ "%%writefile graph.py\n", "from collections import OrderedDict\n", + "from enum import Enum # Python 2 users: Run pip install enum34\n", + "\n", + "\n", + "class State(Enum):\n", + " unvisited = 1\n", + " visited = 2\n", + " visiting = 3\n", "\n", "\n", "class Node:\n", "\n", " def __init__(self, id):\n", " self.id = id\n", - " self.visited = False\n", + " self.visit_state = State.unvisited\n", " self.adjacent = OrderedDict() # key = node, val = weight\n", "\n", " def __str__(self):\n",