要求使用list实现stack类:
共5个空
练习题要求补全横线处缺失的代码,实在是没有思路,求高人指点给答案,多谢!急!

Python程序填空练习题求解答!急!
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- starlight_2007 2022-12-25 16:39关注
class Stack: def __init__(self): self.__elements = [] # Return true if the stack is empty def isEmpty(self): return True #(A) # Returns the element at the top of the stack # without removing it from the stack. def peek(self): if self.isEmpty(): return None else: return self.__elements #(B) # Stores an element into the top of the stack def push(self, value): self.__elements.append(value) #(C) # Removes the element at the top of the stack and returns it def pop(self): if self.isEmpty(): return None else: return self.__elements.pop(0) #(D) # Return the size of the stack def getSize(self): return len(self.__elements) #(E)
试试?
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报 编辑记录