当前位置: 首页>>代码示例>>Python>>正文


Python Node.right方法代码示例

本文整理汇总了Python中tree.Node.right方法的典型用法代码示例。如果您正苦于以下问题:Python Node.right方法的具体用法?Python Node.right怎么用?Python Node.right使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tree.Node的用法示例。


在下文中一共展示了Node.right方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from tree import Node [as 别名]
# 或者: from tree.Node import right [as 别名]
def main():
    root = Node(0)
    root.right = Node(1)
    print is_binary_search_tree(root, -float("inf"), float("inf"))
    root = Node(0)
    root.right = Node(2)
    root.right.left = Node(1)
    root.right.right = Node(1)
    print is_binary_search_tree(root, -float("inf"), float("inf"))
开发者ID:SageBerg,项目名称:CrackingTheCodingInterviewProblems,代码行数:11,代码来源:4.5.py

示例2: main

# 需要导入模块: from tree import Node [as 别名]
# 或者: from tree.Node import right [as 别名]
def main():
    root = Node(0)
    root.left = Node(-10)
    root.left.left = Node(-20)
    root.left.right = Node(-5)
    root.left.left.right = Node(-15)
    root.right = Node(10)
    print lca(root, -15, -5)
开发者ID:SageBerg,项目名称:TechInterviewPractice,代码行数:10,代码来源:lowest_common_ancestor.py

示例3: main

# 需要导入模块: from tree import Node [as 别名]
# 或者: from tree.Node import right [as 别名]
def main():
    root = Node(0)
    root.left = Node(-10)
    root.left.left = Node(-20)
    root.left.right = Node(-5)
    root.right = Node(10)
    root.right.right = Node(20)
    print get_tree_median(root)
开发者ID:SageBerg,项目名称:TechInterviewPractice,代码行数:10,代码来源:halfway_through_tree.py

示例4: main

# 需要导入模块: from tree import Node [as 别名]
# 或者: from tree.Node import right [as 别名]
def main():
    root = Node(0)
    root.left = Node(1)
    root.left.left = Node(2)
    root.right = Node(1)
    root.right.right = Node(2)
    root.right.right.right = Node(3)
    root.right.left = Node(2)
    print is_balanced(root)
开发者ID:SageBerg,项目名称:CrackingTheCodingInterviewProblems,代码行数:11,代码来源:4.1.py

示例5: createMinTree

# 需要导入模块: from tree import Node [as 别名]
# 或者: from tree.Node import right [as 别名]
def createMinTree(low,high):
	if(low>high):
		return
	mid = (low + high)/2
	data = treeElements[mid]
	node = Node(data)
	node.left = createMinTree(low,mid-1)
	node.right = createMinTree(mid+1,high)
	return node
开发者ID:nirmalvp,项目名称:algos,代码行数:11,代码来源:minheighttree.py

示例6: main

# 需要导入模块: from tree import Node [as 别名]
# 或者: from tree.Node import right [as 别名]
def main():
    root = Node(0)
    root.left = Node(1)
    root.right = Node(2)
    root.left.left = Node(3)
    root.left.right = Node(4)
    root.right.left = Node(5)
    root.right.right = Node(6)
    for i in range(7):
        print bfs(root, i), "\n"
开发者ID:SageBerg,项目名称:TechInterviewPractice,代码行数:12,代码来源:bfs.py

示例7: build_tree

# 需要导入模块: from tree import Node [as 别名]
# 或者: from tree.Node import right [as 别名]
def build_tree(lst):
    if lst == []:
        return
    middle = len(lst) / 2
    left_list = lst[:middle]
    right_list = []
    if len(lst) > 1:
        right_list = lst[middle + 1:]
    node = Node(lst[middle])
    node.left = build_tree(left_list)
    node.right = build_tree(right_list)
    return node
开发者ID:SageBerg,项目名称:CrackingTheCodingInterviewProblems,代码行数:14,代码来源:4.3.py

示例8: main

# 需要导入模块: from tree import Node [as 别名]
# 或者: from tree.Node import right [as 别名]
def main():
    root = Node(0)
    root.left = Node(-2)
    root.left.right = Node(-1) 
    root.right = Node(1)
    root.right.right = Node(2)
    lists_dict = dict()
    fill_linked_lists_dict(root, lists_dict, 0)
    i = 0
    while i in lists_dict:
        lst = lists_dict[i]
        ll_node = lst.head
        while ll_node != None:
            print ll_node.data
            ll_node = ll_node.nxt
        i += 1
        print
开发者ID:SageBerg,项目名称:CrackingTheCodingInterviewProblems,代码行数:19,代码来源:4.4.py

示例9: parse

# 需要导入模块: from tree import Node [as 别名]
# 或者: from tree.Node import right [as 别名]
def parse(data, ttable=None, treename=None):
    """
    Parse a newick string.

    *data* is any file-like object that can be coerced into shlex, or
    a string (converted to StringIO)

    *ttable* is a dictionary mapping node labels in the newick string
     to other values.

    Returns: the root node.
    """
    from tree import Node, Tree
    
    if type(data) in types.StringTypes:
        data = StringIO(data)
    
    start_pos = data.tell()
    tokens = Tokenizer(data)

    node = None; root = None
    lp=0; rp=0; rooted=1

    previous = None

    ni = 0 # node id counter (preorder) - zero-based indexing
    li = 0 # leaf index counter
    ii = 0 # internal node index counter
    pi = 0 # postorder sequence
    while 1:
        token = tokens.get_token()
        if token == ';' or token == tokens.eof:
            assert lp == rp, \
                   "unbalanced parentheses in tree description: (%s, %s)" \
                   % (lp, rp)
            break

        # internal node
        elif token == '(':
            lp = lp+1
            newnode = Node()
            newnode.ni = ni; ni += 1
            ## newnode.isleaf = False
            newnode.treename = treename
            if node:
                if node.children: newnode.left = node.children[-1].right+1
                else: newnode.left = node.left+1
                node.add_child(newnode)
            else:
                newnode.left = 1
            newnode.right = newnode.left+1
            node = newnode

        elif token == ')':
            rp = rp+1
            node = node.parent
            if node.children:
                node.right = node.children[-1].right + 1
            
        elif token == ',':
            node = node.parent
            if node.children:
                node.right = node.children[-1].right + 1
            
        # branch length
        elif token == ':':
            token = tokens.get_token()
            if token == '[':
                node.length_comment = tokens.parse_embedded_comment()
                token = tokens.get_token()

            if not (token == ''):
                try: brlen = float(token)
                except ValueError:
                    raise ValueError, ("invalid literal for branch length, "
                                       "'%s'" % token)
            else:
                raise 'NewickError', \
                      'unexpected end-of-file (expecting branch length)'

            node.length = brlen
        # comment
        elif token == '[':
            node.comment = tokens.parse_embedded_comment()
            if node.comment[0] == '&':
                # metadata
                meta = META.findall(node.comment[1:])
                if meta:
                    node.meta = {}
                    for k, v in meta:
                        v = eval(v.replace('{','(').replace('}',')'))
                        node.meta[k] = v

        # leaf node or internal node label
        else:
            if previous != ')': # leaf node
                if ttable:
                    try:
                        ttoken = (ttable.get(int(token)) or
                                  ttable.get(token))
#.........这里部分代码省略.........
开发者ID:ChriZiegler,项目名称:cython-experiments-1,代码行数:103,代码来源:newick.py

示例10: _fit_recursive

# 需要导入模块: from tree import Node [as 别名]
# 或者: from tree.Node import right [as 别名]
    def _fit_recursive(self, X, cluster, node=None):
        """Recursive helper for fit()

        skkdj

        Parameters
        ----------

        Returns
        -------
        """
        if X.shape[0] < 2:
            # base case
            # must have > 2 obs to cluster!
            return Node(self.Leaf(cluster.name, cluster.indices))

        # ---------------------------------------------------------------------
        # use ward w/ (1-corr) to hierarcically cluster to split
        # ---------------------------------------------------------------------
        split = _ward_cluster(X)

        # ---------------------------------------------------------------------
        # train/test svm (radial kernal on 100 random 50/50 splits of clustering
        # ---------------------------------------------------------------------
        try:
            scores = _test_clusters(X, split, stratified=self.stratified)
        except ValueError:
            # base case
            # two few of second class to split (say 9:1 or something)
            # assign entire population to terminal cluster
            return Node(self.Leaf(cluster.name, cluster.indices))

        # ---------------------------------------------------------------------
        # if min(score) < tol (0.80 in glif paper), recursively repeat 3-5 on
        # each subpopulation
        # ---------------------------------------------------------------------
        score = scores.min()
        if score < self.tol:
            # base case
            # assign entire population to terminal cluster
            return Node(self.Leaf(cluster.name, cluster.indices))


        # recursively split
        a = np.where(split == 1)
        b = np.where(split == 2)

        A = self.Cluster(cluster.indices[a], score, cluster.name + "1", len(a[0]))
        B = self.Cluster(cluster.indices[b], score, cluster.name + "2", len(b[0]))

        # add score to binary tree
        if node is None:
            node = Node(self.Split(cluster.name, (A.name, B.name), score, cluster.size))
        else:
            # tree is built pre order
            raise ValueError("Should be null!!!")

        node.left = self._fit_recursive(X[a], A, node.left)
        node.right = self._fit_recursive(X[b], B, node.right)

        return node
开发者ID:jknox13,项目名称:cortical_paper,代码行数:63,代码来源:clustering.py

示例11: Node

# 需要导入模块: from tree import Node [as 别名]
# 或者: from tree.Node import right [as 别名]
from tree import Node
from tree import Tree
n1 = Node(1)
n2 = Node(2)
n3 = Node(3)
n4 = Node(4)
n5 = Node(5)
n6 = Node(6)
n7 = Node(7)
n8 = Node(8)
n1.left =n2
n1.right=n3
n2.left= n4
n2.right = n5
n3.left= n6
n3.right= n7
n4.left= n8
n8.left= Node(9)
tree = Tree(n1)
#tree.printTree()
#print "size of tree"
#print tree.sizeOfTree(tree.root)
#print "depth of tree"
#print tree.depth(tree.root)
#tree.root = tree.deleteTree(tree.root)
#tree.root = tree.mirror(tree.root)
#tree.printTree()
#tree.root= tree.mirror(tree.root)
#tree.levelOrder()
#tree.printAllRootLeafPaths(tree.root,[tree.root.value])
#tree.levelOrder()
开发者ID:prateek1404,项目名称:AlgoPractice,代码行数:33,代码来源:driver.py


注:本文中的tree.Node.right方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。