Question: PYTHON CODE MODIFICATION ONLY FOR THE FOLLOWING INSTRUCTION. THE STRUCTURE OF THE CODE IS PROVIDES BELOW import numpy as npfrom Interfaces import List class ArrayList(List):

PYTHON CODE MODIFICATION ONLY FOR THE FOLLOWING INSTRUCTION.

THE STRUCTURE OF THE CODE IS PROVIDES BELOW

List: Add 5 elements in different positions (including the first and last)

import numpy as npfrom Interfaces import List

class ArrayList(List): ''' ArrayList: Implementation of a Listinterface using Arrays. ''' def __init__(self): ''' __init__: Initialize the state (array,n and j). ''' self.n = 0 self.j = 0 self.a = self.new_array(1) def new_array(self, n : int) ->np.array: ''' new_array: Create a new array of sizen Input: n: the size of the newarray Return: An array of size n ''' return np.zeros(n, np.object) def resize(self): ''' resize: Create a new array and copy theold values. ''' pass

def get(self, i : int) -> object: ''' get: returns the element at positioni Inputs: i: Index that is integernon negative and at most n ''' pass

def set(self, i : int, x : object) ->object: ''' set: Set the value x at the indexi. Inputs: i: Index that is integernon negative and at most n x: Object type, i.e., anyobject ''' pass

def append(self, x : object) : self.add(self.n, x) def add(self, i : int, x : object) : ''' add: shift one positionall the items j>=i, insert an element at position i of the listand increment the number of elements in the list Inputs: i: Indexthat is integer non negative and at most n x: Objecttype, i.e., any object ''' pass def remove(self, i : int) -> object: pass

def size(self) -> int: return self.n

def __str__(self): s = "[" for i in range(0, self.n): s += "%r" % self.a[(i +self.j) % len(self.a)] if i

def __getitem__(self, i) -> object: ''' __getitem__: Returns theitem in the position i in array format, i.e., l[i] where l is a listinstance Input: i: positiveinteger less than n Return: the item at indexi ''' if isinstance(i, slice): return [self.get(i) for iin range(i.start, i.stop)] else: return self.get(i)

def __iter__(self): self.iterator = 0 return self

def __next__(self): if self.iterator < self.n: x = self.a[(self.iterator+ self.j) % len(self.a)] self.iterator +=1 else: raiseStopIteration() return x

'''arraylist = ArrayList()arraylist.append("a")arraylist.append("b")arraylist.append("c")arraylist.append("d")arraylist.append("e")arraylist.append("f")arraylist.append("g")arraylist.append("h")

'''

List: Add 5 elements in different positions (including the first and last) and check that they are in order, e.g., add(0, 4), add(0, 1), add(1, 3), add(1, 2), and add(4, 5). Then get(i) should return i + 1. Remove 2 elements, e.g., index 2 and 3 and the final array should be "1,2,4".

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

ANSWER Here is a sequence of operations that meets the requirements you specified Cr... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Electrical Engineering Questions!