Skip to content

Instantly share code, notes, and snippets.

@gunnarig
Created February 4, 2019 11:52
Show Gist options
  • Save gunnarig/c66f3773678ae01078216d308b38b26e to your computer and use it in GitHub Desktop.
Save gunnarig/c66f3773678ae01078216d308b38b26e to your computer and use it in GitHub Desktop.
class IndexOutOfBounds(Exception):
pass
class NotFound(Exception):
pass
class Empty(Exception):
pass
class ArrayList:
def __init__(self):
self.__size = 8
self.__capacity = 12
self.__index = 0
self.__arr = ["A","A","A","A","A","A","A","A",None,None,None,None]#[None] * self.__capacity
#Time complexity: O(n) - linear time in size of list
def print(self):
# TODO: remove 'pass' and implement functionality
pass
#Time complexity: O(n) - linear time in size of list
def prepend(self, value):
# TODO: remove 'pass' and implement functionality
pass
#[1,"a",3,"b",5,"c",7,"d",None,None,None,None]
#
#Time complexity: O(n) - linear time in size of list
def insert(self, value, index):
if self.__capacity == self.__size:
self.__size * self.__capacity
return ArrayList.insert(self,value,index)
elif self.__capacity >= self.__size:
count = 1
while index >= count:
if count != index:
self.__arr[self.__size+1-count] = self.__arr[self.__size-count]
count += 1
elif count == index:
self.__arr[index-1] = value
break
#Time complexity: O(1) - constant time
def append(self, value):
# TODO: remove 'pass' and implement functionality
pass
#Time complexity: O(1) - constant time
def set_at(self, value, index):
# TODO: remove 'pass' and implement functionality
pass
#Time complexity: O(1) - constant time
def get_first(self):
# TODO: remove 'pass' and implement functionality
pass
#Time complexity: O(1) - constant time
def get_at(self, index):
# TODO: remove 'pass' and implement functionality
pass
#Time complexity: O(1) - constant time
def get_last(self):
# TODO: remove 'pass' and implement functionality
pass
#Time complexity: O(n) - linear time in size of list
def resize(self):
# TODO: remove 'pass' and implement functionality
pass
#Time complexity: O(n) - linear time in size of list
def remove_at(self, index):
# TODO: remove 'pass' and implement functionality
pass
#Time complexity: O(1) - constant time
def clear(self):
# TODO: remove 'pass' and implement functionality
pass
#Time complexity: O(n) - linear time in size of list
#Time complexity: O(log n) - logarythmic time in size of list
def insert_ordered(self, value):
# TODO: remove 'pass' and implement functionality
pass
#Time complexity: O(n^2) - quadratic time in size of list
#Time complexity: O(n log n) - linear times logarythmic time in size of list
def sort(self):
# TODO: remove 'pass' and implement functionality
pass
#Time complexity: O(n) - linear time in size of list
#Time complexity: O(log n) - logarythmic time in size of list
def find(self, value):
# TODO: remove 'pass' and implement functionality
pass
#Time complexity: O(n) - linear time in size of list
#Time complexity: O(log n) - logarythmic time in size of list
def remove_value(self, value):
# TODO: remove 'pass' and implement functionality
pass
def main():
goat = ArrayList()
goat.insert('b',5)
print(goat)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment