Fixed Length Arrays: Addition
0:00:00
Create an Array
class simulating the functionality of fixed-size arrays. The array’s size is 6
. The array’s constructor is already defined:
class Array:
def __init__(self):
pass # Dynamically added to avoid tampering
self._count = 0
self._array = [None, None, None, None, None, None]
self._MAX_CAPACITY = 6
There is no need to implement the constructor. In the code editor, __init__
will contain pass
. The constructor’s code will be added dynamically to avoid any changes.
The Array
class should have the following methods:
__len__()
: Returns the length of the array. For example, if the array is[1, 2, None, None, None, None, None]
,__len__()
will return2
.__getitem__(index)
: Returns the element at the specified index. Raises anIndexError
when the index is out of range.emplace_back(element)
: Places an element at the back of the array. Raises anArrayFull
exception when the array is full (length > 6).emplace_front(element)
: Places an element at the front of the array. Raises anArrayFull
exception when the array is full (length > 6).emplace(element, index)
: Places an element at the specified index. Raises anArrayFull
exception when the array is full (length > 6).
Note: ArrayFull
is already implemented. To raise it, simply use raise ArrayFull()
.
Personalized based on your user activity, skill level, and preferences.
.
.
.
.
Comments