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


Python Stack.isEmpty方法代码示例

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


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

示例1: parChecker

# 需要导入模块: import Stack [as 别名]
# 或者: from Stack import isEmpty [as 别名]
def parChecker(symbolString):
	s=Stack()
	balanced = True # default
	index =0 
	while index < len(symbolString) and balanced:
		symbol=symbolString[index]
		# if (,{,[ push onto stack
		if symbol in "({[":
			s.push(symbol)
		else:
			# if stack is empty, imbalance 
			if s.isEmpty():
				balanced = False
			else:
				top=s.pop()
				if not matches(top,symbol):
					balanced = False

		index = index+1

	# balanced and no ( present 
	if balanced and s.isEmpty():
		return True
	# otherwise unbalanced ( present
	else:
		return False
开发者ID:lbovard,项目名称:python_stuff,代码行数:28,代码来源:par_check.py

示例2: donusum

# 需要导入模块: import Stack [as 别名]
# 或者: from Stack import isEmpty [as 别名]
def donusum(String):
    s=Stack()
    a=[]
    j=0
    sonuc=0
    for i in String:
        a=a+[i]
    if a[0]== "0":
        if a[1]=="b":
            print "ikilik taban"
            for i in a[2:]:
                x=int(i)
                s.push(x)
            while not s.isEmpty():
                b=s.pop()
                sonuc=sonuc+b*math.pow(2,j)
                j+=1
        elif a[1]=="x":
            print "onaltilik taban"
            for i in a[2:]:
                s.push(i)
            
            while not s.isEmpty():
                b=s.pop()
                if b=="A":
                    sonuc=sonuc+10*math.pow(16,j)
                elif b=="B":
                    sonuc=sonuc+11*math.pow(16,j)
                elif b=="C":
                    sonuc=sonuc+12*math.pow(16,j)
                elif b=="D":
                    sonuc=sonuc+13*math.pow(16,j)
                elif b=="E":
                    sonuc=sonuc+14*math.pow(16,j)
                elif b=="F":
                    sonuc=sonuc+15*math.pow(16,j)
                else:
                    x=int(b)
                    sonuc=sonuc+x*math.pow(16,j)
                j+=1
        else:
            print"sekizlik taban"
            for i in a[1:]:
                x=int(i)
                s.push(x)
            while not s.isEmpty():
                b=s.pop()
                sonuc=sonuc+b*math.pow(8,j)
                j+=1
    elif a[0] !="0":
        print "onluk taban"
        sonuc =int(String)
    print "sonuc =", sonuc
开发者ID:esrazngn,项目名称:veriyapilari,代码行数:55,代码来源:donusum.py

示例3: NewStack

# 需要导入模块: import Stack [as 别名]
# 或者: from Stack import isEmpty [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: revrse

# 需要导入模块: import Stack [as 别名]
# 或者: from Stack import isEmpty [as 别名]
def revrse(expr):
	revsd=[]
	stck=Stack()
	for each in expr:
		stck.push(each)
	while stck.isEmpty() is not True:
		revsd.append(stck.pop())
	print ''.join(revsd)
开发者ID:sanchiaman,项目名称:python_github,代码行数:10,代码来源:reverseTheString.py

示例5: SortStack

# 需要导入模块: import Stack [as 别名]
# 或者: from Stack import isEmpty [as 别名]
def SortStack(mystack):
	HelpStack = Stack()
	while not mystack.isEmpty():
		MaxValue = mystack.pop()
		while not HelpStack.isEmpty() and HelpStack.peek() > MaxValue:
			mystack.push(HelpStack.pop())
		HelpStack.push(MaxValue)

	return HelpStack
开发者ID:Jason-Yuan,项目名称:Interview-Code,代码行数:11,代码来源:Chapter3-6.py

示例6: dec_to_base

# 需要导入模块: import Stack [as 别名]
# 或者: from Stack import isEmpty [as 别名]
def dec_to_base(dec, base):
	digits = "0123456789ABCDEF"
	s = Stack()
	while dec > 0:
		s.push(dec % base)
		dec = dec / base
	yeni = ""
	while not s.isEmpty():
		yeni = yeni + digits[s.pop()]
		
	return yeni
开发者ID:mctr,项目名称:pro-lang,代码行数:13,代码来源:dec_to_base.py

示例7: parChecker

# 需要导入模块: import Stack [as 别名]
# 或者: from Stack import isEmpty [as 别名]
def parChecker(symbolString):
    s = Stack()
    balanced = True
    index = 0
    while index < len(symbolString) and balanced:
        symbol = symbolString[index]
        if symbol in "([{":
            print "symbol:::",symbol
            s.push(symbol)
        else:
            if s.isEmpty():
                balanced = False
            else:
                tp = s.pop()
                print "top:::",tp
                if not matches(tp,symbol):
                       balanced = False
        index = index + 1
    if balanced and s.isEmpty():
        return True
    else:
        return False
开发者ID:jeevan449,项目名称:MyPracticeCode,代码行数:24,代码来源:parchecker.py

示例8: parChecker

# 需要导入模块: import Stack [as 别名]
# 或者: from Stack import isEmpty [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

示例9: decTo

# 需要导入模块: import Stack [as 别名]
# 或者: from Stack import isEmpty [as 别名]
	def decTo(self):
		digits = "0123456789ABCDEF"
		remstack = Stack()

		while self.val > 0:
			rem = self.val % self.base
			remstack.push(rem)
			self.val = self.val / self.base

		newOne = ""
		while not remstack.isEmpty():
			newOne = newOne + digits[remstack.pop()]

		return newOne
开发者ID:wemrekurt,项目名称:Python,代码行数:16,代码来源:decTo.py

示例10: bracketChecker

# 需要导入模块: import Stack [as 别名]
# 或者: from Stack import isEmpty [as 别名]
def bracketChecker(user_input):
    s = Stack()
    for c in user_input:
        if c == ("(" or "[" or "{"):
            s.push(c)
        elif c == (")" or "]" or "}"):
            if s.isEmpty():
                return False
            else:
                top = s.pop()
                if not matches(top, c):
                    return False
        else:
            pass
    return True
开发者ID:keachico,项目名称:CS303E_and_CS313E,代码行数:17,代码来源:stack_bracketCheck.py

示例11: infixToPostfix

# 需要导入模块: import Stack [as 别名]
# 或者: from Stack import isEmpty [as 别名]
def infixToPostfix(infixexpr):
    # First set up a dictionary mapping symbols to
    # precedence.
    prec = {}
    prec["*"]= 3
    prec["/"]= 3
    prec["+"]= 2
    prec["-"]= 2
    prec["("]= 1
    # Split the input into tokens.
    tokenList = infixexpr.split()
    # We’ll need a stack and an output stream.
    opStack = Stack()
    outputList = []
    for token in tokenList:
        # Is token a number?
        if token.isdigit():
            outputList.append(token)
        elif token == "(":
            opStack.push(token)
        elif token == ")":
            topToken = opStack.pop()
            while topToken != "(":
                outputList.append(topToken)
                topToken = opStack.pop()
        else:
            while (not opStack.isEmpty()) and \
                  (prec[opStack.peek()] >= prec[token]):
                outputList.append(opStack.pop())

            opStack.push(token)
                                
    while not opStack.isEmpty():
        outputList.append(opStack.pop())
    #print(" ".join(outputList))
    return " ".join(outputList)
开发者ID:keachico,项目名称:CS303E_and_CS313E,代码行数:38,代码来源:Calculator.py

示例12: DFS_iterative

# 需要导入模块: import Stack [as 别名]
# 或者: from Stack import isEmpty [as 别名]
def DFS_iterative(Graph, node, nodes_list):
    global time
    stack = Stack()
    stack.push(node)
    while not stack.isEmpty():
        nodes_list[node].explore()
        nodes_list[node].set_leader(source_node)
        node = stack.peek()
        if len(Graph[node]) != 0:
            linked_node = Graph[node].pop()
            if nodes_list[linked_node].get_not_explored():
                stack.push(linked_node)
        else:
            time += 1
            nodes_list[stack.pop()].set_time(time)
开发者ID:LorenzoBi,项目名称:algorithm_design,代码行数:17,代码来源:Kosaraju_algorithm.py

示例13: __repr__

# 需要导入模块: import Stack [as 别名]
# 或者: from Stack import isEmpty [as 别名]
    def __repr__(self):
        m = self.m
        if m == 1 or m == 0:
            raise Exception("Si le facteur de compression est de 0 ou de 1, il est impossible de créer un arbre fini.")
        stack = Stack()
        current = self.__urn
        stack.push(current)
	    

        while current.getSize() != 1:           #push chaque niveau de l'arbre sur le stack
	    
            current = current.getCompressed(m)
            stack.push(current)
            
	
        f = Queue()
        root = stack.pop().getBallot(0)         #initialisation à la racine de l'arbre (taille du premier niveau = 1)
        tree = Forest(str(root))

        f.insert(tree)
        
        while not stack.isEmpty():              #tant qu'il y a des niveaux à rajouter
                     
            level = stack.pop()                     #niveau à lier au niveau précédent
            i = 0
            toModify = f.size()                     #nombre de noeuds du niveau précédent
            while i < toModify:
                
                n = f.remove()
                node = level.getBallot(i*m)
                n.modifyChild(str(node))    #on ajoute un premier fils
                f.insert(n.getChild())                                  #on le mémorise pour modifier son fils par après
                                    
                j=1
                n = n.getChild()
                while (j < m and (i*m)+j < level.getSize()):            #on ajoute m-1 frère(s) à ce fils
                    node = level.getBallot(i*m+j)
                    n.modifyBrother(str(node))  #on ajoute un frère
                    f.insert(n.getBrother())                                #on le mémorise pour modifier son fils par après
                    n = n.getBrother()                                      #n devient le frère de n afin de lui ajouter un frère à l'itération suivante
                    j+=1

                i += 1
                
        tree.niveau(m)
        return ""
开发者ID:aureooms-ulb-2010-2015,项目名称:2010-2011-infof103-project-3,代码行数:48,代码来源:CountingTree.py

示例14: balanced

# 需要导入模块: import Stack [as 别名]
# 或者: from Stack import isEmpty [as 别名]
def balanced(expr):
	stck=Stack()
	for each in expr:
		if typeOfPara(each) is "lpar1" or typeOfPara(each) is "lpar2" or typeOfPara(each) is "lpar3":
			typ=typeOfPara(each)
			stck.push(typ)
		elif typeOfPara(each) is "rpar1" or typeOfPara(each) is "rpar2" or typeOfPara(each) is "rpar3":
			typ=typeOfPara(each)
			spop=stck.pop()
			if match(spop)==typ:
				continue
			else:
				break


	if stck.isEmpty() is not True:
		print "Unbalanced Paranthesis"
	else:
		print "Balanced Paranthesis"
开发者ID:sanchiaman,项目名称:python_github,代码行数:21,代码来源:balancedParanthesis.py

示例15: toRegularTree

# 需要导入模块: import Stack [as 别名]
# 或者: from Stack import isEmpty [as 别名]
    def toRegularTree(self,numberOfChildren = 2):   #1) je ne vois pas en quoi le second paramètre est nécessaire,
                                                    #   le résultat de la méthode n'est d'ailleurs pas logique si
                                                    #   numberOfChildren est différent de 2
                                                    #   je ne lui ai donné aucun rôle dans cette méthode afin d'éviter de potentielles erreurs
                                                    #2) je ne crée pas l'arbre binaire à partir de l'arbre courant
                                                    #   car si jamais (et ce n'est pas le cas dans les tests fournis)
                                                    #   on désire créer un arbre m-aire avec m > 2 en tant qu'arbre courant,
                                                    #   on sera obligé de partir du niveau le plus bas.. cad l'urne de départ..
	
        stack = Stack()
        current = self.__urn
        stack.push(current)
	    
        while current.getSize() != 1:           #push chaque niveau de l'arbre sur le stack
	    
            current = current.getCompressed(2)
            stack.push(current)
            
	
        f = Queue()
        root = stack.pop().getBallot(0)     #initialisation à la racine de l'arbre (taille du premier niveau = 1)
        tree = BinaryTree(str(root)+str(root.getIdentifier()))
        f.insert(tree)
        
        while not stack.isEmpty():          #tant qu'il y a des niveaux à rajouter
                     
            level = stack.pop()                 #niveau à lier au niveau précédent
            i = 0
            toModify = f.size()                 #nombre de noeuds du niveau précédent
            while i < toModify:                 #on ajoute un fils gauche et un fils droit à chacun de ces noeuds(un gauche minimum)       
                n = f.remove()
                node = level.getBallot(i*2)              #indice du fils gauche = indice du père * 2
                n.insertLeft(str(node) + str(node.getIdentifier()))     #ajout d'un fils gauche
                f.insert(n.getLeftChild())                              #on ajoute le fils à la liste des noeuds qui doivent être modifiés
                if i*2+1 < level.getSize():                
                    node = level.getBallot(i*2+1)        #indice du fils droit = indice du père * 2 + 1
                    n.insertRight(str(node) + str(node.getIdentifier()))#ajout d'un fils droit
                    f.insert(n.getRightChild())                         #on ajoute le fils à la liste des noeuds qui doivent être modifiés
                i += 1

        return tree
开发者ID:aureooms-ulb-2010-2015,项目名称:2010-2011-infof103-project-3,代码行数:43,代码来源:CountingTree.py


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