本文整理汇总了Python中pythonds.basic.stack.Stack.push方法的典型用法代码示例。如果您正苦于以下问题:Python Stack.push方法的具体用法?Python Stack.push怎么用?Python Stack.push使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pythonds.basic.stack.Stack
的用法示例。
在下文中一共展示了Stack.push方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: chkid_allrecord
# 需要导入模块: from pythonds.basic.stack import Stack [as 别名]
# 或者: from pythonds.basic.stack.Stack import push [as 别名]
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'
示例2: infixToPostfix
# 需要导入模块: from pythonds.basic.stack import Stack [as 别名]
# 或者: from pythonds.basic.stack.Stack import push [as 别名]
def infixToPostfix(infixexpr):
prec = {}
prec['*'] = 3
prec['/'] = 3
prec['+'] = 2
prec['-'] = 2
prec['('] = 1
opStack = Stack()
postfixList = []
tokenList = infixexpr.split()
for token in tokenList:
if token in 'ABCDEFGHIJKLMNOPQRSTUMWXYZ' or token in '0123456789':
postfixList.append(token)
elif token == '(':
opStack.push(token)
elif token == ')':
topToken = opStack.pop()
while topToken != '(':
postfixList.append(topToken)
topToken = opStack.pop()
else:
while (not opStack.isEmpty()) and (prec[opStack.peek()] >= prec[token]):
postfixList.append(opStack.pop())
opStack.push(token)
while not opStack.isEmpty():
postfixList.append(opStack.pop())
return ' '.join(postfixList)
示例3: match_parenthesis
# 需要导入模块: from pythonds.basic.stack import Stack [as 别名]
# 或者: from pythonds.basic.stack.Stack import push [as 别名]
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)))
示例4: infixToPostfix
# 需要导入模块: from pythonds.basic.stack import Stack [as 别名]
# 或者: from pythonds.basic.stack.Stack import push [as 别名]
def infixToPostfix(infixexpr):
prec = {}
prec["^"] = 4
prec["*"] = 3
prec["/"] = 3
prec["+"] = 2
prec["-"] = 2
prec["("] = 1
opStack = Stack()
postfixList = []
tokenList = infixexpr.split()
for token in tokenList:
if token in string.ascii_uppercase or token in string.digits:
postfixList.append(token)
elif token == "(":
opStack.push(token)
elif token == ")":
topToken = opStack.pop()
while topToken != "(":
postfixList.append(topToken)
topToken = opStack.pop()
else:
while (not opStack.isEmpty()) and (prec[opStack.peek()] >= prec[token]):
postfixList.append(opStack.pop())
opStack.push(token)
while not opStack.isEmpty():
postfixList.append(opStack.pop())
return " ".join(postfixList)
示例5: parChecker
# 需要导入模块: from pythonds.basic.stack import Stack [as 别名]
# 或者: from pythonds.basic.stack.Stack import push [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 False
示例6: parse_num
# 需要导入模块: from pythonds.basic.stack import Stack [as 别名]
# 或者: from pythonds.basic.stack.Stack import push [as 别名]
def parse_num(list):
no_operator = re.split(r'[(+)notandor]', list)
no_operator = [i for i in no_operator if i != '']
no_operand = re.split(r'[0123456789]', list)
no_oper = []
parsed = []
p = Stack()
count = 0
for i in range(len(no_operand)):
if no_operand[i] == "(":
p.push(no_operand[i])
if no_operand[i] in ['+', '-', '*', '/', ')', 'not', 'and', 'or']:
if p.peek() != '':
p.push('')
p.push(no_operand[i])
else:
p.push(no_operand[i])
if no_operand[i] == '':
if p.peek() != '':
p.push('')
no_oper = p.items
for i in range(len(no_oper)):
if no_oper[i] != '':
parsed.append(no_oper[i])
else:
parsed.append(no_operator[count])
count += 1
return parsed
示例7: infixToPostfix
# 需要导入模块: from pythonds.basic.stack import Stack [as 别名]
# 或者: from pythonds.basic.stack.Stack import push [as 别名]
def infixToPostfix(infixexpr):
prec = {}
prec["*"] = 3
prec["/"] = 3
prec["+"] = 2
prec["-"] = 2
prec["("] = 1
opStack = Stack()
postfixList = []
tokenList = infixexpr.split()
for token in tokenList:
if token in "ABCDEFGHIJKLMNOPQRSTUVWXYZ" or token in "0123456789":
postfixList.append(token)
elif token == '(':
opStack.push(token)
elif token == ')':
topToken = opStack.pop()
while topToken != '(':
postfixList.append(topToken)
topToken = opStack.pop()
else:
while (not opStack.isEmpty()) and \
(prec[opStack.peek()] >= prec[token]):
postfixList.append(opStack.pop())
opStack.push(token)
while not opStack.isEmpty():
postfixList.append(opStack.pop())
return " ".join(postfixList)
示例8: infixToPostfix
# 需要导入模块: from pythonds.basic.stack import Stack [as 别名]
# 或者: from pythonds.basic.stack.Stack import push [as 别名]
def infixToPostfix(infixexpr):
prec = {'*': 3, '/': 3, '+': 2, '-': 2, '(': 1, '^': 4}
postfixList = []
opStack = Stack()
tokenList = infixexpr.split()
for token in tokenList:
if token in string.uppercase or token.isdigit():
postfixList.append(token)
elif token == '(':
opStack.push(token)
elif token == ')':
top = opStack.pop()
while top != '(':
postfixList.append(top)
top = opStack.pop()
else:
while not opStack.isEmpty() and prec[opStack.peek()] >= prec[token]:
postfixList.append(opStack.pop())
opStack.push(token)
while not opStack.isEmpty():
postfixList.append(opStack.pop())
return " ".join(postfixList)
示例9: infix_to_postfix
# 需要导入模块: from pythonds.basic.stack import Stack [as 别名]
# 或者: from pythonds.basic.stack.Stack import push [as 别名]
def infix_to_postfix(self, infixexpr):
opStack = Stack()
postfixList = []
tokenList = infixexpr.split()
for token in tokenList:
if BoolParser.isBoolVariable(token):
# if token is a boolean variable, just append to list
postfixList.append(token)
elif token == '(':
# start a new nested expression in the stack
opStack.push(token)
elif token == ')':
# end the nested expression by moving the operators
# from the stack to the list (i.e. in reverse order)
topToken = opStack.pop()
while topToken != '(':
postfixList.append(topToken)
topToken = opStack.pop()
else:
while (not opStack.isEmpty()) and \
(BoolParser.PREC[opStack.peek()] >= BoolParser.PREC[token]):
postfixList.append(opStack.pop())
opStack.push(token)
while not opStack.isEmpty():
postfixList.append(opStack.pop())
return postfixList
示例10: chkid_len
# 需要导入模块: from pythonds.basic.stack import Stack [as 别名]
# 或者: from pythonds.basic.stack.Stack import push [as 别名]
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'
示例11: match_parenthesis
# 需要导入模块: from pythonds.basic.stack import Stack [as 别名]
# 或者: from pythonds.basic.stack.Stack import push [as 别名]
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)))
示例12: infixToPostfix
# 需要导入模块: from pythonds.basic.stack import Stack [as 别名]
# 或者: from pythonds.basic.stack.Stack import push [as 别名]
def infixToPostfix(infixexpr):
prec = {'^': 4, '*': 3, '/': 3, '+': 2, '-': 2, '(': 1}
opStack = Stack()
postfixList = []
tokenList = infixexpr.split()
for token in tokenList:
if token in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' or token in '1234567890':
postfixList.append(token)
elif token == '(':
opStack.push('(')
elif token == ')':
topToken = opStack.pop()
while topToken != '(':
postfixList.append(topToken)
topToken = opStack.pop()
else:
while (not opStack.isEmpty() ) and (prec[opStack.peek()] >= prec[token]):
postfixList.append(opStack.pop())
opStack.push(token)
while not opStack.isEmpty():
postfixList.append(opStack.pop())
return ''.join(postfixList)
示例13: revstring
# 需要导入模块: from pythonds.basic.stack import Stack [as 别名]
# 或者: from pythonds.basic.stack.Stack import push [as 别名]
def revstring(mystr):
myStack = Stack()
for i in mystr:
myStack.push(i)
revstr = ''
while not myStack.isEmpty():
revstr = revstr + myStack.pop()
return revstr
示例14: sortstacks
# 需要导入模块: from pythonds.basic.stack import Stack [as 别名]
# 或者: from pythonds.basic.stack.Stack import push [as 别名]
def sortstacks(astack):
temp=Stack()
while not astack.isEmpty():
tmp=astack.pop()
while temp.peek()<tmp:
temp.pop()
temp.push(tmp)
return temp
示例15: revstring_mine
# 需要导入模块: from pythonds.basic.stack import Stack [as 别名]
# 或者: from pythonds.basic.stack.Stack import push [as 别名]
def revstring_mine(mystr):
s = Stack()
for char in mystr:
s.push(char)
revstr = ''
while not s.isEmpty():
revstr += s.pop()
return revstr