-
Notifications
You must be signed in to change notification settings - Fork 0
/
cache.py
47 lines (40 loc) · 884 Bytes
/
cache.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
37
38
39
40
41
42
43
44
45
46
47
from copy import deepcopy
class Node:
def __init__(self,value):
self.value = value
self.next = None
class List:
def __init__(self):
self.head = None
def insert_top(self,x):
if self.head == None:
self.head = x
else:
self._insert_top(x)
def _insert_top(self,x):
temp = self.head
while temp.next is not None:
temp = temp.next
temp.next = x
def delete_head(self):
if self.head.next is not None:
temp = self.head.next
self.head = temp
else:
self.head = None
def delete_top(self):
temp = self.head
while temp.next.next is not None:
temp = temp.next
del(temp.next)
temp.next = None
def step_back(cache,box,cache_size):
if cache_size > 2:
temp = cache.head
while temp.next is not None:
temp = temp.next
box.atoms = deepcopy(temp.value)
box.update_visual_atoms()
cache.delete_top()
cache_size -=1
return cache_size