當前位置: 首頁>>代碼示例>>Python>>正文


Python stack.Stack方法代碼示例

本文整理匯總了Python中stack.Stack方法的典型用法代碼示例。如果您正苦於以下問題:Python stack.Stack方法的具體用法?Python stack.Stack怎麽用?Python stack.Stack使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在stack的用法示例。


在下文中一共展示了stack.Stack方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: is_paren_balanced

# 需要導入模塊: import stack [as 別名]
# 或者: from stack import Stack [as 別名]
def is_paren_balanced(paren_string):
    s = Stack()
    is_balanced = True
    index = 0

    while index < len(paren_string) and is_balanced:
        paren = paren_string[index]
        if paren in "([{":
            s.push(paren)
        else:
            if s.is_empty():
                is_balanced = False
            else:
                top = s.pop()
                if not is_match(top, paren):
                    is_balanced = False
        index += 1

    if s.is_empty() and is_balanced:
        return True
    else:
        return False 
開發者ID:vprusso,項目名稱:youtube_tutorials,代碼行數:24,代碼來源:stack_balanced_parens.py

示例2: __init__

# 需要導入模塊: import stack [as 別名]
# 或者: from stack import Stack [as 別名]
def __init__(self, embs, relations, tokens, dependencies, alignments, oracle, hooks, variables, stage, rules):
        self.semicol_gen_and = False
        self.hooks = hooks
        self.variables = variables
        self.buffer = Buffer(embs, tokens, alignments)
        self.embs = embs
        self.stage = stage
        self.dependencies = Dependencies([(self.buffer.tokens[i1],label,self.buffer.tokens[i2]) for (i1,label,i2) in dependencies])
        self.stack = Stack(embs)
        self.oracle = oracle
        self.rules = rules
        if relations is not None:
            self.gold = Relations(copy.deepcopy(relations))
        else:
            self.gold = None
        self.sentence = " ".join([t.word for t in tokens])
        self.counter = 0 
開發者ID:mdtux89,項目名稱:amr-eager,代碼行數:19,代碼來源:state.py

示例3: treeParser

# 需要導入模塊: import stack [as 別名]
# 或者: from stack import Stack [as 別名]
def treeParser(string: str)->TreeNode:
    string = string.split()
    tree = TreeNode()
    stack: Stack = Stack()
    currentTree: TreeNode = tree
    stack.push(tree)
    for item in string:
        if item == "(":
            currentTree.insertLeft()
            stack.push(currentTree)
            currentTree = currentTree.getLeftChild()
        elif item == ")":
            currentTree = stack.pop()
        elif item in "+-*/":
            currentTree.setRootValue(item)
            currentTree.insertRight()
            stack.push(currentTree)
            currentTree = currentTree.getRightChild()
        elif pattern.match(item):
            currentTree.setRootValue(int(item))
            currentTree = stack.pop()
        else:
            raise ValueError()
    
    return tree 
開發者ID:ivanmmarkovic,項目名稱:Problem-Solving-with-Algorithms-and-Data-Structures-using-Python,代碼行數:27,代碼來源:exercise04-inorder.py

示例4: div_by_2

# 需要導入模塊: import stack [as 別名]
# 或者: from stack import Stack [as 別名]
def div_by_2(dec_num):
    if dec_num == 0:
        return 0
    s = Stack()

    while dec_num > 0:
        remainder = dec_num % 2
        s.push(remainder)
        dec_num = dec_num // 2

    bin_num = ""
    while not s.is_empty():
        bin_num += str(s.pop())

    return bin_num 
開發者ID:vprusso,項目名稱:youtube_tutorials,代碼行數:17,代碼來源:stack_divide_by_two.py

示例5: test_push

# 需要導入模塊: import stack [as 別名]
# 或者: from stack import Stack [as 別名]
def test_push(self):
        test_stack = stack.Stack()
        with self.assertRaises(ValueError):
            test_stack.peek()

        test_value = 22
        test_stack.push(test_value)
        self.assertEquals(test_value, test_stack.peek()) 
開發者ID:QuantumFractal,項目名稱:Data-Structure-Zoo,代碼行數:10,代碼來源:test.py

示例6: test_pop

# 需要導入模塊: import stack [as 別名]
# 或者: from stack import Stack [as 別名]
def test_pop(self):
        test_stack = stack.Stack()
        test_value = 42
        test_stack.push(test_value)

        self.assertEquals(test_value, test_stack.pop()) 
開發者ID:QuantumFractal,項目名稱:Data-Structure-Zoo,代碼行數:8,代碼來源:test.py

示例7: test_peek

# 需要導入模塊: import stack [as 別名]
# 或者: from stack import Stack [as 別名]
def test_peek(self):
        test_stack = stack.Stack()

        test_value = 22
        test_stack.push(test_value)
        self.assertEquals(test_value, test_stack.peek()) 
開發者ID:QuantumFractal,項目名稱:Data-Structure-Zoo,代碼行數:8,代碼來源:test.py

示例8: test_size

# 需要導入模塊: import stack [as 別名]
# 或者: from stack import Stack [as 別名]
def test_size(self):
        test_stack = stack.Stack()

        test_stack.push('Woo!')
        test_stack.push('This is fun!')
        test_stack.push('Wow! I love reading UnitTests!')

        self.assertEquals(3, test_stack.size) 
開發者ID:QuantumFractal,項目名稱:Data-Structure-Zoo,代碼行數:10,代碼來源:test.py

示例9: __init__

# 需要導入模塊: import stack [as 別名]
# 或者: from stack import Stack [as 別名]
def __init__(self, **kwargs):
        self.name = ''
        self.tx_fields = []
        self.tx_serializer = transaction.TransactionSerializer
        self.block_header_fields = list(_bitcoin_header_fields)
        self.block_fields = list(_bitcoin_block_fields)
        self.opcode_overrides = list(_bitcoin_opcode_overrides)
        self.script_engine_cls = stack.Stack
        self.opcode_names = dict(OPCODE_NAMES)
        self.opcodes_by_name = dict(OPCODES_BY_NAME)
        self.disabled_opcodes = list(DISABLED_OPCODES)

        for k, v in kwargs.items():
            setattr(self, k, v) 
開發者ID:mazaclub,項目名稱:hashmal,代碼行數:16,代碼來源:chainparams.py

示例10: set_opcode_overrides

# 需要導入模塊: import stack [as 別名]
# 或者: from stack import Stack [as 別名]
def set_opcode_overrides(ops):
    """Set the overridden behavior of specified opcodes.

    This affects all Stack steps that run afterward.
    """
    opcodes.set_overridden_opcodes(ops) 
開發者ID:mazaclub,項目名稱:hashmal,代碼行數:8,代碼來源:chainparams.py

示例11: test_init

# 需要導入模塊: import stack [as 別名]
# 或者: from stack import Stack [as 別名]
def test_init(self):
        s = Stack()
        assert s.peek() is None
        assert s.length() == 0
        assert s.is_empty() is True 
開發者ID:Make-School-Courses,項目名稱:CS-1.3-Core-Data-Structures,代碼行數:7,代碼來源:stack_test.py

示例12: test_init_with_list

# 需要導入模塊: import stack [as 別名]
# 或者: from stack import Stack [as 別名]
def test_init_with_list(self):
        s = Stack(['A', 'B', 'C'])
        assert s.peek() == 'C'
        assert s.length() == 3
        assert s.is_empty() is False 
開發者ID:Make-School-Courses,項目名稱:CS-1.3-Core-Data-Structures,代碼行數:7,代碼來源:stack_test.py

示例13: test_length

# 需要導入模塊: import stack [as 別名]
# 或者: from stack import Stack [as 別名]
def test_length(self):
        s = Stack()
        assert s.length() == 0
        s.push('A')
        assert s.length() == 1
        s.push('B')
        assert s.length() == 2
        s.pop()
        assert s.length() == 1
        s.pop()
        assert s.length() == 0 
開發者ID:Make-School-Courses,項目名稱:CS-1.3-Core-Data-Structures,代碼行數:13,代碼來源:stack_test.py

示例14: test_push

# 需要導入模塊: import stack [as 別名]
# 或者: from stack import Stack [as 別名]
def test_push(self):
        s = Stack()
        s.push('A')
        assert s.peek() == 'A'
        assert s.length() == 1
        s.push('B')
        assert s.peek() == 'B'
        assert s.length() == 2
        s.push('C')
        assert s.peek() == 'C'
        assert s.length() == 3
        assert s.is_empty() is False 
開發者ID:Make-School-Courses,項目名稱:CS-1.3-Core-Data-Structures,代碼行數:14,代碼來源:stack_test.py

示例15: test_peek

# 需要導入模塊: import stack [as 別名]
# 或者: from stack import Stack [as 別名]
def test_peek(self):
        s = Stack()
        assert s.peek() is None
        s.push('A')
        assert s.peek() == 'A'
        s.push('B')
        assert s.peek() == 'B'
        s.pop()
        assert s.peek() == 'A'
        s.pop()
        assert s.peek() is None 
開發者ID:Make-School-Courses,項目名稱:CS-1.3-Core-Data-Structures,代碼行數:13,代碼來源:stack_test.py


注:本文中的stack.Stack方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。