Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modify your list implementation so that the size of the underlying array is dynamic. The base size of the array is 20 and should never

Modify your list implementation so that the size of the underlying array is dynamic. The base size of the array is 20 and should never be less than 20. However, if the list becomes full, it is resized to be 2 times larger than the current size. Likewise, the underlying size should decrease by half if the underlying array is larger than the base size but the content occupies less than 1 of the available space. When resizing the 1/8 list, retain the contents of the list. That is, when it is initially filled, it will be resized to 20 items, then 40,while retaining the contents initially in it. The same happens when the size of the array shrinks. MY CODE ARE IN PYTHON

My code is :

and code for

referential_array can get at https://repl.it/@MuhammadFermi/week6-1 or
import ctypes def build_array(size):  if size <= 0: raise ValueError("Array size should be larger than 0.") if not isinstance(size, int): raise ValueError("Array size should be an integer.") array = (size * ctypes.py_object)() array[:] = size * [None] return array 
from referential_array import build_array class ArrayList: Array = None size = 0 def __init__(self, size): self.Array = build_array(size) self.size = size def __str__(self): string = "" for i in self.Array: if (i != None): string = string + str(i) + " " return string def __len__(self): return self.size def __contains__(self, item): for i in self.Array: if i == item: return True return False def __getitem__(self, index): index = int(index) if (index > -self.size and index < self.size): if (index < 0): return (self.Array[self.size + index]) else: return (self.Array[index]) else: raise ValueError("Index is out of range") def __setitem__(self, index, item): index = int(index) if (index > -self.size and index < self.size): if (index < 0): self.Array[self.size + index] = item else: self.Array[index] = item else: raise ValueError("Index is out of range") def __eq__(self, other): return self == other def append(self, item): for i in range(0, self.size): if (self.Array[i] == None): self.Array[i] = item return raise ValueError("List is full") def insert(self, index, item): index = int(index) if (index > -self.size and index < self.size): if (index < 0): self.Array[self.size + index - 1] = item else: self.Array[index - 1] = item else: raise ValueError("Index is out of range") def remove(self, item): for i in self.Array: if (i == item): self.Array[i] = None return raise ValueError("List is empty") def delete(self, index): index = int(index) if (index > -self.size and index < self.size): if (index < 0): for i in range(self.size + index, self.size - 1): self.Array[i] = self.Array[i + 1] else: for i in range(index, self.size - 1): self.Array[i] = self.Array[i + 1] else: raise ValueError("Index is out of range") 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 11 The Database For Big Data And Analytics

Authors: Cristian Molaro, Surekha Parekh, Terry Purcell, Julian Stuhler

1st Edition

1583473858, 978-1583473856

More Books

Students also viewed these Databases questions

Question

If so, what type of information?

Answered: 1 week ago

Question

1. Are we excluding potential customers or employees?

Answered: 1 week ago

Question

1. Communicating courses and programs to employees.

Answered: 1 week ago

Question

6. Testing equipment that will be used in instruction.

Answered: 1 week ago