9wo. 2022-12-25 00:23 采纳率: 100%
浏览 35
已结题

Python程序填空练习题求解答!急!

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

img

  • 写回答

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)
    

    试试?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录

报告相同问题?

问题事件

  • 系统已结题 1月2日
  • 已采纳回答 12月25日
  • 创建了问题 12月25日

悬赏问题

  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持