题目
题目
单项选择题

Stacks_PhPP_4 Below is function written for Stack ADT ,  the Stack ADT is implemented using a Python's list. Which function is this? Assume Empty is implemented. def mystery(self): if self.is_empty(): raise Empty('Stack is empty')    return self._data[-1]   Below is the STACK ADTs' constructor: class ArrayStack: """LIFO Stack implementation using a Python list as underlying storage.""" def __init__(self): """Create an empty stack.""" self._data = [] # nonpublic list instance

选项
A.pop
B.top
C.push
D.return self._data[-1]
查看解析

查看解析

标准答案
Please login to view
思路分析
To begin, let's understand what mystery(self) is doing. It first checks if the stack is empty, and raises an Empty exception in that case. If not empty, it returns the last element of the underlying list, self._data[-1], which corresponds to the top of the stack in a LIFO structure since the end of the list is treated as the top. Option 1: pop - This option suggests the function would remove and ......Login to view full explanation

登录即可查看完整答案

我们收录了全球超50000道考试原题与详细解析,现在登录,立即获得答案。

更多留学生实用工具

加入我们,立即解锁 海量真题独家解析,让复习快人一步!