Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

def insert(self, i, element): ------------------------------------------------------- A copy of element is inserted at index i, following data items are shifted to the right. If i

def insert(self, i, element): """ ------------------------------------------------------- A copy of element is inserted at index i, following data items are shifted to the right. If i is outside of range of -len(List) to len(List) - 1, the method halts by calling assertion. Note: Python allows negative indices for Python list and we want to support it for our List implementation

Use: lst.insert(i, element) ------------------------------------------------------- Parameters: i - index value (int) element - a data element (?) Returns: True if insert is successful, False otherwise. ------------------------------------------------------- """ assert self._is_valid_index(i), "invalid indices"

assert self._count< self._capacity, "List is full"

#TODO: make it work for negative index #TODO: if array is full

#insert if there is room in place j = 0 if i == self._count: #insertion at end of array self._values[i] = deepcopy(element) else: #general insertion for j in range(self._count, i-1, -1): #shift element to make space for new element self._values[j] = self._values[j-1] self._values[i] = deepcopy(element) self._count += 1 #increment number of elements return

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

Step: 3

blur-text-image

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

Spatio Temporal Database Management International Workshop Stdbm 99 Edinburgh Scotland September 10 11 1999 Proceedings Lncs 1678

Authors: Michael H. Bohlen ,Christian S. Jensen ,Michel O. Scholl

1999th Edition

3540664017, 978-3540664017

More Books

Students also viewed these Databases questions

Question

Question What are the requirements for a SIMPLE 401(k) plan?

Answered: 1 week ago