亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

對 python 中的 size() 函數感到困惑

對 python 中的 size() 函數感到困惑

一只名叫tom的貓 2022-10-18 17:55:54
我正在通過代碼在python中編寫一個循環隊列class CircularQueue:  # constructor for the class  # taking input for the size of the Circular queue   # from user  def __init__(self, maxSize):    self.queue = list()    # user input value for maxSize    self.maxSize = maxSize    self.head = 0    self.tail = 0  # add element to the queue  def enqueue(self, data):    # if queue is full    if self.size() == (self.maxSize - 1):      return("Queue is full!")    else:      # add element to the queue      self.queue.append(data)      # increment the tail pointer      self.tail = (self.tail+1) % self.maxSize      return True讓我困惑的部分是“入隊”方法中的 self.size()我查看了 python 文檔,沒有看到任何 size() 函數,只在 numpy.xml 中引用了 size() 。通常你會想調用 len() 來獲取列表的大小,但我知道你不能這樣做 self.len()寫這樣的東西背后的語法和邏輯的任何清晰/解釋都會有幫助!
查看完整描述

1 回答

?
aluckdog

TA貢獻1847條經驗 獲得超7個贊

您需要定義自己的 size() 方法并返回當前隊列中的項目數。



查看完整回答
反對 回復 2022-10-18
  • 1 回答
  • 0 關注
  • 225 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號