예제 #1
0
파일: graph.py 프로젝트: noahpieta/juncBASE
 def test(g):
     "Graph test program."
     print Graph.test.__doc__
     g.addVertex(0)
     g.addVertex(1)
     g.addVertex(2)
     g.addEdge(0, 1)
     g.addEdge(0, 2)
     g.addEdge(1, 2)
     print g
     print "isDirected returns " + str(g.isDirected)
     print "Using vertex iterator"
     for v in g.vertices:
         print v
     print "Using edge iterator"
     for e in g.edges:
         print e
     visitor = PrintingVisitor()
     print "DepthFirstTraversal"
     g.depthFirstTraversal(PreOrder(visitor), 0)
     visitor.finish()
     print "BreadthFirstTraversal"
     g.breadthFirstTraversal(visitor, 0)
     visitor.finish()
     print "isConnected returns " + str(g.isConnected)
예제 #2
0
파일: tree.py 프로젝트: noahpieta/juncBASE
 def test(tree):
     "Tree test program."
     print Tree.test.__doc__
     visitor = PrintingVisitor()
     print tree
     print "Breadth-First traversal"
     tree.breadthFirstTraversal(visitor)
     visitor.finish()
     print "Preorder traversal"
     tree.depthFirstTraversal(PreOrder(visitor))
     visitor.finish()
     print "Inorder traversal"
     tree.depthFirstTraversal(InOrder(visitor))
     visitor.finish()
     print "Postorder traversal"
     tree.depthFirstTraversal(PostOrder(visitor))
     visitor.finish()
     print "Using iterator"
     for i in tree:
         print i
     print "Using depth-first generator (preorder)"
     for i in tree.depthFirstGenerator(Tree.PREORDER):
         print i
     print "Using breadth-first generator"
     for i in tree.breadthFirstGenerator():
         print i
예제 #3
0
 def test(tree):
     "SearchTree test program."
     for i in range(1, 8):
         tree.insert(i)
     visitor = PrintingVisitor()
     print(tree)
     print("Breadth-first traversal")
     tree.breadthFirstTraversal(visitor)
     visitor.finish()
     print("Preorder traversal")
     tree.depthFirstTraversal(PreOrder(visitor))
     visitor.finish()
     print("Inorder traversal")
     tree.depthFirstTraversal(InOrder(visitor))
     visitor.finish()
     print("Postorder traversal")
     tree.depthFirstTraversal(PostOrder(visitor))
     visitor.finish()
     print("Using iterator")
     for i in tree:
         print(i)
     print("Using depth-first generator")
     for i in tree.depthFirstGenerator(Tree.INORDER):
         print(i)
     print("Using breadth-first generator")
     for i in tree.breadthFirstGenerator():
         print(i)
     print("Withdrawing 4")
     obj = tree.find(4)
     try:
         tree.withdraw(obj)
         print(tree)
     except NotImplementedError:
         print("Withdraw not implemented.")
예제 #4
0
 def test(g):
     "Digraph test program."
     print Digraph.test.__doc__
     Graph.test(g)
     visitor = PrintingVisitor()
     print "TopologicalOrderTraversal"
     g.topologicalOrderTraversal(visitor)
     visitor.finish()
     print "isCyclic returns " + str(g.isCyclic)
     print "isStronglyConnected returns " + str(g.isStronglyConnected)