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


Python stack.Stack类代码示例

本文整理汇总了Python中pythonds.basic.stack.Stack的典型用法代码示例。如果您正苦于以下问题:Python Stack类的具体用法?Python Stack怎么用?Python Stack使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: chkid_allrecord

	def chkid_allrecord(self,m,rr1):
			# que = "SELECT * FROM wp_2015ptainsuracelist where frm_id='%s';" % (rr1)
			# rr=m.db.query(que)
			idData = (str(rr1),)
			que = """SELECT * FROM """+self.table+""" where frm_id==?"""
			rr=m.dbsql3.data_query(que,idData,False)
			print rr
			p = Stack()
			print(rr)
			if rr:
				for i in rr[0]:
					p.push(i)
				rrr=p.seek()
				OR = rrr[18]
				ins = rrr[16]
				reg = rrr[15]
				trans = rrr[19]
				print "Pass chkid_allrecord!******************"
				if OR=='' and ins==0 and reg==0 and trans=='':
					return 'False1',rrr
				if OR!='' and ins==0 and trans!='':
					return 'True1',rrr
				if OR!='' and ins!=0 and trans!='':
					return 'True2',rrr
			else:
				return 'False2'
开发者ID:maestrom4,项目名称:must-pta2,代码行数:26,代码来源:func.py

示例2: chkid_len

	def chkid_len(self,main,a,b=None,c=None,d=None,e=False):

		if e:
			if len(a)==8 or len(a)==10 or a.count('x')==4:
				return True
			else:
				self.alert(main,'ID Less than 8 or 10!','ID length allowed is 8 or 10 \n You have #'+str(len(a))+' digits.')
				return False
		else:
			print("self table===="+self.table)
			print("Check by name is activated!")
			# que = "SELECT * FROM wp_2015ptainsuracelist where frm_stdname='%s' AND frm_std_middle_name='%s' AND frm_std_last_name='%s';" % (b,c,d)
			que = """SELECT * FROM """+self.table+""" where frm_stdname=? AND frm_std_middle_name=? AND frm_std_last_name=?"""
			fullname = (str(b),str(c),str(d))
			rr=main.dbsql3.data_query(que,fullname)
			p = Stack()
			print(b+" "+c+" "+d)
			print("student name! search")
			print(rr)
			if rr:
				for i in rr[0]:
					p.push(i)
				rrr=p.seek()
				OR = rrr[18]
				ins = rrr[16]
				reg = rrr[15]
				trans = rrr[19]
				if OR=='' and ins==0 and reg==0 and trans=='':
					return 'False1'
				if OR!='' and ins==0 and trans!='':
					return 'True1',rrr
				if OR!='' and ins!=0 and trans!='':
					return 'True2',rrr
			else:
				return 'False2'
开发者ID:maestrom4,项目名称:must-pta2,代码行数:35,代码来源:func.py

示例3: revstring_mine

def revstring_mine(mystr):
    s = Stack()
    for char in mystr:
        s.push(char)
    revstr = ''
    while not s.isEmpty():
        revstr += s.pop()
    return revstr
开发者ID:xkal36,项目名称:Algorithms,代码行数:8,代码来源:string_reversal_stack.py

示例4: revstring

def revstring(mystr):
	s = Stack()
	new_mystr = ''
	for i in mystr:
		s.push(i)
	while not s.isEmpty():
		new_mystr = new_mystr+s.pop()
	return new_mystr
开发者ID:yuelingjiang,项目名称:workspace,代码行数:8,代码来源:algorithm2.py

示例5: revstring

def revstring(mystr):
    myStack = Stack()
    for i in mystr:
      myStack.push(i)
      revstr = ''
    while not myStack.isEmpty():
      revstr = revstr + myStack.pop()
    return revstr
开发者ID:bradleyscot,项目名称:cookbook,代码行数:8,代码来源:reverse_string.py

示例6: revstring

def revstring(mystr):
    # your code here
    reversed = ""
    string_stack = Stack()
    for char in mystr:
        string_stack.push(char)
    while not string_stack.isEmpty():
        last = string_stack.pop()
        reversed += last
    return reversed
开发者ID:cforan99,项目名称:challenges,代码行数:10,代码来源:revstr_stack.py

示例7: match_parenthesis

def match_parenthesis (symbolString):
  ## close any and all open parenthesises & return a "file" to be processed further... 
  from pythonds.basic.stack import Stack
  s = Stack()
  balanced = True
  index = 0
  while index < len(symbolString) and balanced:
        symbol = symbolString[index]
        if symbol == "(":
            s.push(symbol+ str(index))
        elif symbol == ")":
            if s.isEmpty():
                balanced = False
            else:
                s.pop()

        index = index + 1

  if balanced and s.isEmpty():
        #print ("it is FINALLY balanced!")
        return symbolString
  elif balanced and not s.isEmpty():
        #print "opening barace is not closed at " 
        
        idx = int (s.pop().strip("("))
        #print idx
        #print symbolString[idx]
        return (match_parenthesis(removeExtra(symbolString,idx))) 
  else:   #couldn't pop from stack
        #print "extra closing present at"
        #print index
        return (match_parenthesis(removeExtra(symbolString,index-1))) 
开发者ID:tanksha,项目名称:external-tools,代码行数:32,代码来源:sumo-importer.py

示例8: buildParseTree

def buildParseTree(fpexp):
    fplist = fpexp.split()
    pStack = Stack()
    eTree = BinaryTree('')
    pStack.push(eTree)
    currentTree = eTree
    for i in fplist:
        if i == '(':            
            currentTree.insertLeft('')
            pStack.push(currentTree)
            currentTree = currentTree.getLeftChild()
        elif i not in ['+', '-', '*', '/', ')']:  
            currentTree.setRootVal(int(i))
            parent = pStack.pop()
            currentTree = parent
        elif i in ['+', '-', '*', '/']:       
            currentTree.setRootVal(i)
            currentTree.insertRight('')
            pStack.push(currentTree)
            currentTree = currentTree.getRightChild()
        elif i == ')':          
            currentTree = pStack.pop()
        else:
            raise ValueError
    return eTree
开发者ID:ErikRHanson,项目名称:Problem-Solving-with-Algorithms-and-Data-Structures-Using-Python,代码行数:25,代码来源:parsetree.py

示例9: buildParseTree

def buildParseTree(fpexp):
    fplist = fpexp.split()
    pStack = Stack()
    eTree = BinaryTree("")
    pStack.push(eTree)
    currentTree = eTree
    for i in fplist:
        if i == "(":
            currentTree.insertLeft("")
            pStack.push(currentTree)
            currentTree = currentTree.getLeftChild()
        elif i not in ["+", "-", "*", "/", ")"]:
            currentTree.setRootVal(int(i))
            parent = pStack.pop()
            currentTree = parent
        elif i in ["+", "-", "*", "/"]:
            currentTree.setRootVal(i)
            currentTree.insertRight("")
            pStack.push(currentTree)
            currentTree = currentTree.getRightChild()
        elif i == ")":
            currentTree = pStack.pop()
        else:
            raise ValueError
    return eTree
开发者ID:arunkamaraj,项目名称:learning,代码行数:25,代码来源:tree_trial.py

示例10: match_parenthesis

def match_parenthesis(symbolString):
    ## close any and all open parenthesises & return a "file" to be processed further... 
    from pythonds.basic.stack import Stack
    s = Stack()
    balanced = True
    index = 0
    while index < len(symbolString) and balanced:
        symbol = symbolString[index]
        if symbol == "(":
            s.push(symbol+ str(index))
        elif symbol == ")":
            if s.isEmpty():
                balanced = False
            else:
                s.pop()

        index = index + 1

    if balanced and s.isEmpty():
        return symbolString
    elif balanced and not s.isEmpty():
        idx = int (s.pop().strip("("))
        return (match_parenthesis(removeExtra(symbolString,idx)))
    else:   #couldn't pop from stack
        return (match_parenthesis(removeExtra(symbolString,index-1)))
开发者ID:TScottJ,项目名称:external-tools,代码行数:25,代码来源:kifparser.py

示例11: divide_by_2

def divide_by_2(num):
    rem_stack = Stack() # putting my stack in action

    while num > 0:
        rem = num % 2 # remainder variable
        rem_stack.push(rem) # push the remainder in my stack
        num = num // 2 # divide my num by two

    bin_string = '' # create my binary string
    while not rem_stack.isEmpty():
        bin_string = bin_string + str(rem_stack.pop()) # pop the remainder from my stack
    return bin_string # get my binary string
开发者ID:Martondegz,项目名称:python-snippets,代码行数:12,代码来源:binary.py

示例12: revString

def revString(astring):
    s = Stack() #create a new stack
    
    for ch in astring:
        s.push(ch)
    
    reverse_string = ''

    for i in range(len(astring)):
        reverse_string = reverse_string + s.pop()
        
    return reverse_string
开发者ID:herokyar,项目名称:algorithms_Python,代码行数:12,代码来源:reverse_string_by_stack.py

示例13: divide_by_two

def divide_by_two(decimal):
    stack = Stack()

    while decimal > 0:
        remainder = decimal % 2
        stack.push(remainder)
        decimal = decimal // 2

    binary = ''
    while not stack.isEmpty():
        binary += str(stack.pop())

    return binary
开发者ID:arosenberg01,项目名称:toy-problems,代码行数:13,代码来源:decimal-to-binary.py

示例14: divideBy2

def divideBy2(decNumber):
    remstack = Stack()

    while decNumber > 0:
        rem = decNumber % 2
        remstack.push(rem)
        decNumber = decNumber // 2

    binString = ""
    while not remstack.isEmpty():
        binString = binString + str(remstack.pop())

    return binString
开发者ID:teddymcw,项目名称:pythonds_algos,代码行数:13,代码来源:stacks.py

示例15: revstring

def revstring(sg):
    s = Stack()

    lst = [i for i in sg]
    res = []

    for c in lst:
        s.push(c)

    while not s.isEmpty():
        res.append(s.pop())

    return "".join(res)
开发者ID:gr8h,项目名称:competitive_programming_py,代码行数:13,代码来源:revstring.py


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