-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsorted_lists.py
38 lines (27 loc) · 1.02 KB
/
sorted_lists.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
from typing import List
from journey_pointer import JourneyPointer
class SortedJourneyList(object):
""" List of JourneyPointer, sorted in descending order of arrival time """
def __init__(self, data: List[JourneyPointer]):
self.data = data
def __len__(self):
return len(self.data)
def __getitem__(self, item):
return self.data[item]
def __repr__(self):
return f'<SortedJourneyList of size {len(self.data)}>'
def __str__(self):
return str(self.data)
def append(self, e: JourneyPointer):
"""
Adds a JourneyPoint to the list
:param e: the element to add
"""
for i, elem in enumerate(self.data):
if elem.arrival_time <= e.arrival_time:
self.data = self.data[:i] + [e] + self.data[i:]
return
self.data = self.data + [e]
def remove_earliest_arrival(self):
""" Removes the journey pointer with the earliest arrival time in the list """
self.data = self.data[:-1]