forked from octaflop/algosand
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathch2.py
More file actions
42 lines (32 loc) · 774 Bytes
/
ch2.py
File metadata and controls
42 lines (32 loc) · 774 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Super power of ordered arrays
n = 101
binarray = range(n)
# 4 primary operations in an array algo
# Read
# Search
# Insert
# Delete
# This is the most basic code, but will be updated
# with algorithms while we play along.
# Read
def aread(arr, i):
return arr[i]
# Search
def asearch(arr, s):
# TODO, bin_search ;-)
for i, a in enumerate(arr):
if a == s:
return aread(arr, i)
# Insert
def ainsert(arr, i):
# TODO ;-)
# Gonna do this the hard way -- shift right at first
# We'll make it better later.
raise NotImplemented
# Delete
def adelete(arr, i)
# TODO ;-)
# Gonna do this the hard way -- shift right at first
# then remove and shift left.
# We'll make it better later.
raise NotImplemented