夜色资源站www国产在线资源,国产偷窥熟妇高潮呻吟,潮湿的心动漫在线观看免费未删减,欧美日韩国产成人精品

當前位置:考試網  > 試卷庫  > 計算機類  > 等級考試  > 計算機二級  > Python語言程序設計  >  在 Python 中如何實現棧和隊列?請舉例說明。
試題預覽

在 Python 中如何實現棧和隊列?請舉例說明。

查看答案
收藏
糾錯
正確答案:

class Stack(object):

def __init__(self):

self.stack=[]

def isEmpty(self):

return self.stack==[]

def push(self,item):

self.stack.append(item)

def pop(self):

if self.isEmpty():

raise IndexError,'pop from empty stack'

return self.stack.pop()

def peek(self):

return self.stack[-1]

def size(self):

return len(self.stack)

class Queue:

def __init__(self, head=None):

self.storage = [head]

def enqueue(self, new_element):

self.storage.append(new_element)

def peek(self):

return self.storage[0]

def dequeue(self):

return self.storage.pop(0)

答案解析:

暫無解析

你可能感興趣的試題

以下關于字符串類型的操作的描述,錯誤的是:

以下程序的輸出結果是:

deffun1(a,b,*args):

print(a)

print(b)

print(args)

fun1(1,2,3,4,5,6)

以下Python語言關鍵字在異常處理結構中用來捕獲特定類型異常的選項是:

設str='python',想把字符串的第一個字母大寫,其他字母還是小寫,正確的選項是:

用Pyinstall工具把Python源文件打包成一個獨立的可執行文件,使用的參數是:

熱門試題 更多>
試題分類: 藥店相關技能鑒定
練習次數:0次
試題分類: 理論與實務
練習次數:0次
掃一掃,手機做題