-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharray.py
36 lines (27 loc) · 783 Bytes
/
array.py
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
class Array:
def __init__(self, length):
self.value = None
if length:
self.next = Array(length-1)
def set_value(self, pos, value):
if not pos:
self.value = value
return value
return self.next.set_value(pos-1, value)
def get_value(self, pos):
if not pos:
return self.value
return self.next.get_value(pos-1)
if __name__ == "__main__":
array = Array(5)
array1 = Array(2)
array.set_value(0, array1)
array1.set_value(0, 6)
array2 = array.get_value(0)
array2.set_value(0, 98)
print(array.get_value(0).get_value(0))
"""
array.set_value(2, 56)
array.set_value(0, 2)
print(f"{ array.get_value(0) } { array.get_value(2) }")
"""