欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

python實(shí)現(xiàn)代數(shù)式括號(hào)有效性檢驗(yàn)-創(chuàng)新互聯(lián)

python實(shí)現(xiàn)代數(shù)式括號(hào)有效性檢驗(yàn)?針對(duì)這個(gè)問(wèn)題,這篇文章詳細(xì)介紹了相對(duì)應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問(wèn)題的小伙伴找到更簡(jiǎn)單易行的方法。

站在用戶的角度思考問(wèn)題,與客戶深入溝通,找到黃陂網(wǎng)站設(shè)計(jì)與黃陂網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:網(wǎng)站設(shè)計(jì)、成都網(wǎng)站設(shè)計(jì)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名注冊(cè)雅安服務(wù)器托管、企業(yè)郵箱。業(yè)務(wù)覆蓋黃陂地區(qū)。

思路:

利用棧實(shí)現(xiàn)代數(shù)式中括號(hào)有效行的的檢驗(yàn):

代碼:

class mychain(object): #利用鏈表建立棧,鏈表為父類
 length=0
 def __init__(self,value=None,next=None):#創(chuàng)建鏈表,長(zhǎng)度并不包含頭部
  self.value=value
  self.next=next
  #mychain.length=mychain.length+1
 def append(self,value=None):
  while self.next!=None:
   self=self.next
  self.next=mychain(value)
  mychain.length=mychain.length+1 #追加時(shí),鏈表長(zhǎng)度增加
 def travle(self):#遍歷鏈表
  print(self.value)
  if self.next!=None:
   self.next.travle()
 def drop (self,value):#刪除特定值的第一個(gè)匹配節(jié)點(diǎn)
  while self.next!=None:
   if self.next.value!=value:
    self=self.next
   else:
    self.next=self.next.next
    mychain.length=mychain.length-1 #刪除時(shí),鏈表長(zhǎng)度減小
    break
 def pop(self):#刪除未節(jié)點(diǎn)
  if self.next!=None:#并不刪除頭結(jié)點(diǎn)
   while self.next.next!=None:
    self=self.next
   self.next=None
   mychain.length=mychain.length-1#彈出為節(jié)點(diǎn),并減小長(zhǎng)度,頭結(jié)點(diǎn)不彈出



class stock(mychain):#棧類
 bottom=None   #棧底
 top=None     #棧頂
 n_count=0    #計(jì)數(shù)
 def Max(self):  #占中大值
  if self.next!=None:
   tmp = self.next.value
   while self.next.next!=None:
    self=self.next
    if self.next.value>tmp:
     tmp=self.next.value
   return tmp
  else:
   print('棧為空!')
 def Min(self):#棧中的最小值
  if self.next!=None:
   tmp = self.next.value
   while self.next.next!=None:
    self=self.next
    if self.next.value<tmp:
     tmp=self.next.value
   return tmp
  else:
   print('棧為空!')

 def push(self,value): #壓棧
  while self.next != None:
   self = self.next
  self.next = mychain(value)
  stock.top=self.next
  stock.length=stock.length+1
  stock.n_count=stock.n_count+1
 def __init__(self,value='',next=None):
  self.value=value
  self.next=next
  stock.bottom=self
  stock.top=self
  #stock.n_count=stock.n_count+1
  #stock.length=stock.length+1
 def append(self,value=''):#取消追加函數(shù)
  print('請(qǐng)使用Push()!')
 def pop(self):
  if self.next!=None:#并不刪除頭結(jié)點(diǎn)
   while self.next.next!=None:
    self=self.next
   self.next=None
   stock.top=self
   stock.length=stock.length-1#彈出為節(jié)點(diǎn),并減小長(zhǎng)度,頭結(jié)點(diǎn)不彈出
class solution(object):
 def validationofbrackets(self,astr=''):#檢驗(yàn)串中的括號(hào)合法性
  braketsstock=stock()
  for i in astr:
   if i in ['{','(','[']:
    braketsstock.push(i)
   else:
    if i==')':
     if braketsstock.top.value=='(':
      braketsstock.pop()
     else:
      return False
    elif i==']':
     if braketsstock.top.value=='[':
      braketsstock.pop()
     else:
      return False
    elif i=='}':
     if braketsstock.top.value=='{':
      braketsstock.pop()
     else:
      return False
    else:
     pass
  print(astr)
  print(braketsstock.length)
  if braketsstock.length==0:
   return True
  else:
   return False

分享標(biāo)題:python實(shí)現(xiàn)代數(shù)式括號(hào)有效性檢驗(yàn)-創(chuàng)新互聯(lián)
文章路徑:http://www.chinadenli.net/article4/dpjpoe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站制作響應(yīng)式網(wǎng)站云服務(wù)器用戶體驗(yàn)網(wǎng)站策劃網(wǎng)站導(dǎo)航

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

綿陽(yáng)服務(wù)器托管