def main(): p1 = Stack() p2 = Stack() p3 = Stack() num_disks = 6 for disk in range(num_disks): p1.push(num_disks - disk) arrange_hanoi(p1, p2, p3, num_disks) print(p1.length(), p2.length(), p3.length())
def dfs_stack(self, v): """ Return a DFS tree from v, using a stack. """ marked = {v: None} stack = Stack() stack.push(v) while stack.length() > 0: vertex = stack.pop() for e in self.get_edges(vertex): w = e.opposite(vertex) if w not in marked: marked[w] = e stack.push(w) return marked
def dfs_stack(self, v): """ Return a DFS tree from v, using a stack. """ marked = {v:None} stack = Stack() stack.push(v) while stack.length() > 0: vertex = stack.pop() for e in self.get_edges(vertex): w = e.opposite(vertex) if w not in marked: marked[w] = e stack.push(w) return marked