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


Python Stack.size方法代码示例

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


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

示例1: buildParseTree

# 需要导入模块: import Stack [as 别名]
# 或者: from Stack import size [as 别名]
def buildParseTree(exp_string):
	exp_list = exp_string.split()
	parent_stack = Stack()
	root = BinaryTree(None)
	current_node = root
	
	for token in exp_list:
		if token == "(":
			current_node.insertLeft(None)
			parent_stack.push(current_node)
			current_node = current_node.getLeftChild()
		
		elif token in "+-*/":
			current_node.setRootVal(token)
			parent_stack.push(current_node)
			current_node.insertRight(None)
			current_node = current_node.getRightChild()
			
		elif token == ")":
			if parent_stack.size() > 0:
				parent_node = parent_stack.pop()
				current_node = parent_node
		
		else:
			current_node.setRootVal(float(token))
			if parent_stack.size() > 0:
				parent_node = parent_stack.pop()
				current_node = parent_node
	
	return root
开发者ID:Xiaoke1982,项目名称:AlgorithmAndDataStructureInPython,代码行数:32,代码来源:ParseTree.py

示例2: __init__

# 需要导入模块: import Stack [as 别名]
# 或者: from Stack import size [as 别名]
class MarbleClock:
    def __init__(self,numMarbles):
        self.resv = Queue()
        self.oneMin = Stack()
        self.fiveMin = Stack()
        self.hour = Stack()

        assert numMarbles >= 27
        
        for i in range(numMarbles):
            self.resv.enqueue(i)

        
            
    def minute(self):
        m = self.resv.dequeue()
        self.oneMin.push(m)
        
        if self.oneMin.size() == 5:
            self.fiveMin.push(self.oneMin.pop())
            for i in range(4):
                d = self.oneMin.pop()
                self.resv.enqueue(d)
        if self.fiveMin.size() == 12:
            f = self.fiveMin.pop()
            self.hour.push(f)
            for i in range(11):
                h = self.fiveMin.pop()
                self.resv.enqueue(h)
        if self.hour.size() == 12:
            for i in range(12):
                hrs = self.hour.pop()
                self.resv.enqueue(hrs)
        self.cap = self.resv
                
    def run12hours(self):
        for i in range(720): #720 because there are 720 minutes in 12 hours
            self.minute()
                      
    def inOrder(self):
        if self.cap == self.resv:
            return True
        
            

    #----------------------------------------------------------------------
    def _getResv(self): #(Python) list of ints

        nums = []
        for i in range(self.resv.size()):
            nums.append(self.resv._front.item)
            self.resv.enqueue(self.resv.dequeue())
        return nums
开发者ID:paulchifita,项目名称:osafunsa,代码行数:55,代码来源:marbleClock.py

示例3: NewStack

# 需要导入模块: import Stack [as 别名]
# 或者: from Stack import size [as 别名]
class NewStack():
	def __init__(self):
		self.Stack = Stack()
		self.minStack = Stack()
		self.tempMin = None

	def isEmpty(self):
		return self.Stack.isEmpty()

	def push(self, item):
		if self.tempMin == None or item < self.tempMin:
			self.tempMin = item
		self.Stack.push(item)
		self.minStack.push(self.tempMin)

	def pop(self):
		self.minStack.pop()
		return self.Stack.pop()

	def min(self):
		return self.minStack.peek()

	def peek(self):
		return self.Stack.peek()

	def size(self):
		return self.Stack.size()
开发者ID:Jason-Yuan,项目名称:Interview-Code,代码行数:29,代码来源:Chapter3-2.py

示例4: infix2postfix

# 需要导入模块: import Stack [as 别名]
# 或者: from Stack import size [as 别名]
def infix2postfix(expr):
	stck=Stack()
	pof_expr=[]
	for each in expr:
		x=typeof(each)
		if x is "lpar":
			stck.push(each)
		elif x is "rpar":
			next_item=stck.pop()
			while typeof(next_item) is not "lpar":
				pof_expr.append(next_item)
				next_item=stck.pop()
		elif x is "oprand":
			pof_expr.append(each)
		elif x is "empty":
			continue
		elif x is "oprator":
			while stck.size() is not 0 and precedence(each)<=precedence(stck.peek()):
				pof_expr.append(stck.pop())
			stck.push(each)

	while stck.size()>0:
		pof_expr.append(stck.pop())
	print ''.join(pof_expr)
开发者ID:sanchiaman,项目名称:python_github,代码行数:26,代码来源:infix2postfix.py

示例5: parChecker

# 需要导入模块: import Stack [as 别名]
# 或者: from Stack import size [as 别名]
def parChecker(symbolString):
	s	= Stack()
	balanced = True
	index =0

	while index < len(symbolString) and balanced:
		symbol = symbolString[index]
		if symbol in "([{":
			s.push(symbol)
		else:
			if s.isEmpty():
				balanced=False
			else:
				top = s.pop()
				if not matches(top,symbol):
					balanced=False

		index=index+1

	if balanced and s.isEmpty():
		return True
	else:
		return s.size()
开发者ID:wemrekurt,项目名称:Python,代码行数:25,代码来源:parChecker.py

示例6: MyQueue

# 需要导入模块: import Stack [as 别名]
# 或者: from Stack import size [as 别名]
class MyQueue(object):
    def __init__(self):
        self.firstStack = Stack()
        self.secondStack = Stack()
        
    def enqueue(self, item):
        self.firstStack.push(item)
        
    def dequeue(self):
        if self.secondStack.size() == 0:
            while self.firstStack.size() > 0:
                self.secondStack.push(self.firstStack.pop())
        return self.secondStack.pop()

    def peek(self):
        if self.secondStack.size() == 0:
            while self.firstStack.size() > 0:
                self.secondStack.push(self.firstStack.pop())
        return self.secondStack.peek()

    def isEmpty(self):
        return self.firstStack.size() == 0 and self.secondStack.size() == 0
开发者ID:Jason-Yuan,项目名称:Interview-Code,代码行数:24,代码来源:Chapter3-5.py

示例7: print

# 需要导入模块: import Stack [as 别名]
# 或者: from Stack import size [as 别名]
print("------------Starting Stack Testing------------")

#Stack

from Stack import *

s = Stack()

#Operations				#Stack Contents			#Return Value
print(s.is_empty()) 	#[] 					True
s.push(4) 				#[4]
s.push('dog') 			#[4,'dog']
print(s.top())			#[4,'dog'] 				'dog'
print(s.push(True)) 	#[4,'dog',True]	
print(s.size()) 		#[4,'dog',True] 		3
print(s.is_empty()) 	#[4,'dog',True] 		False
print(s.push(8.4)) 		#[4,'dog',True,8.4]
print(s.pop()) 			#[4,'dog',True] 		8.4
print(s.pop()) 			#[4,'dog'] 				True
print(s.size()) 		#[4,'dog'] 				2

print("------------Starting Queue Testing------------")

#Queue

from Queue import *

q = Queue()

#Operations 			#Queue Contents 		#Return Value
开发者ID:hshidara,项目名称:Data-Structures,代码行数:32,代码来源:tester.py

示例8: Stack

# 需要导入模块: import Stack [as 别名]
# 或者: from Stack import size [as 别名]
import Stack as Stack

s = Stack()

print(s.isEmpty())
s.push(4)
s.push("dog")
print(s.peek())
s.push(True)
print(s.size())
print(s.isEmpty())
s.push(8.4)
print(s.pop())
print(s.pop())
print(s.size())
开发者ID:dksingh04,项目名称:DataStructure-And-Algorithm,代码行数:17,代码来源:testStack.py


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