class ERModel(object): """Model of a scheduler.""" def __init__(self): self.patients = LinkedPriorityQueue() def isEmpty(self): """Returns True if there are patients in the model or False otherwise. << This didn't make sense. "isEmpty" returns True if empty. fixed in code.""" if self.patients.size == 0: return True else: return False def schedule(self, p): """Adds a patient to the schedule.""" self.patients.add(p) #print("Queue Size: ", self.queue.size) used for traceback #print(self.isEmpty()) used for traceback def treatNext(self): """Returns the patient treated or None if there are none.""" if self.isEmpty(): return None else: temp = self.patients.pop() #print("Queue Size: ", self.queue.size) used for traceback #print(self.isEmpty()) used for traceback return temp
class ERModel(object): """ERmodle""" def __init__(self): self._queue = LinkedPriorityQueue() def isEmpty(self): return self._queue.isEmpty() def schedule(self, patient): self._queue.add(patient) def treatNext(self): patient = self._queue.pop() return patient
class ERModel(object): """模型调度器""" def __init__(self): self._patients_queue = LinkedPriorityQueue() def isEmpty(self): return self._patients_queue.isEmpty() def schedule(self, patient): """增加一个病人""" self._patients_queue.add(patient) def treat_next(self): """删除队头节点""" return self._patients_queue.pop()
class ERModel(object): """Model of a scheduler.""" def __init__(self): self._patients = LinkedPriorityQueue() def isEmpty(self): """Returns True if there are patients in the model or False otherwise.""" return self._patients.isEmpty() def schedule(self, p): """Adds a patient to the schedule.""" self._patients.add(p) def treatNext(self): """Returns the patient treated or None if there are none.""" if self._patients.isEmpty(): return None else: return self._patients.pop()
def test(queueType): # Test any implementation with same code print("VERIFY THAT IT BEHAVES LIKE A REGULAR QUEUE.") q = queueType() print("Length:", len(q)) print("Empty:", q.isEmpty()) print("Add 1-10") for i in range(10): q.add(i + 1) print("Peeking:", q.peek()) print("Items (front to rear):", q) print("Length:", len(q)) print("Empty:", q.isEmpty()) theClone = queueType(q) print("Items in clone (front to rear):", theClone) theClone.clear() print("Length of clone after clear:", len(theClone)) print("Pop 3 items:", end=" ") for count in range(3): print(q.pop(), end=" ") print("\nQueue: ", q) print("Adding 11 and 12:") for item in range(11, 13): q.add(item) print("Queue: ", q) print("Popping items (front to rear): ", end="") while not q.isEmpty(): print(q.pop(), end=" ") print("\nLength:", len(q)) print("Empty:", q.isEmpty()) print("Create with 11 items:") q = queueType(range(1, 12)) print("Items (front to rear):", q) print("\nVERIFY THAT IT BEHAVES LIKE A PRIORITY QUEUE.") lyst = list(range(1, 20, 2)) random.shuffle(lyst) print("The items added: ", lyst) q = LinkedPriorityQueue(lyst) print("The queue: ", q) q.add(16) q.add(17) print("Adding 16 and 17: ", q) print("Add some random strings with random priorities attached:") q.clear() for s in "VERIFY THAT": c = Comparable(s, random.randint(1, 3)) print((c.getData(), c.getPriority())) q.add(c) print("The queue: ", q)
def test(queueType): # Test any implementation with same code print("VERIFY THAT IT BEHAVES LIKE A REGULAR QUEUE.") q = queueType() print("Length:", len(q)) print("Empty:", q.isEmpty()) print("Add 1-10") for i in range(10): q.add(i + 1) print("Peeking:", q.peek()) print("Items (front to rear):", q) print("Length:", len(q)) print("Empty:", q.isEmpty()) theClone = queueType(q) print("Items in clone (front to rear):", theClone) theClone.clear() print("Length of clone after clear:", len(theClone)) print("Pop 3 items:", end = " ") for count in range(3): print(q.pop(), end = " ") print("\nQueue: ", q) print("Adding 11 and 12:") for item in range(11, 13): q.add(item) print("Queue: ", q) print("Popping items (front to rear): ", end="") while not q.isEmpty(): print(q.pop(), end=" ") print("\nLength:", len(q)) print("Empty:", q.isEmpty()) print("Create with 11 items:") q = queueType(range(1, 12)) print("Items (front to rear):", q) print("\nVERIFY THAT IT BEHAVES LIKE A PRIORITY QUEUE.") lyst = list(range(1, 20, 2)) random.shuffle(lyst) print("The items added: ", lyst) q = LinkedPriorityQueue(lyst) print("The queue: ", q) q.add(16) q.add(17) print("Adding 16 and 17: ", q) print("Add some random strings with random priorities attached:") q.clear() for s in "VERIFY THAT": c = Comparable(s, random.randint(1, 3)) print((c.getData(), c.getPriority())) q.add(c) print("The queue: ", q)
def __init__(self): self._patients = LinkedPriorityQueue()
def __init__(self): self.patients = LinkedPriorityQueue()
def __init__(self): self._patients_queue = LinkedPriorityQueue()
def __init__(self, sourceCollection=None): LinkedPriorityQueue.__init__(self, sourceCollection)
def treatNext(self): """Returns the patient treated or None if there are none.""" LinkedPriorityQueue.pop(self)
def schedule(self, p): """Adds a patient to the schedule.""" LinkedPriorityQueue.add(self, p)