def breadthFirstSearch(self, v0, v1): previous = [-1] * self.mNumVariables q = myQueue.Queue() q.enqueue(v0) previous[v0] = v0 path = [] while q.empty() == False: current = q.dequeue() # if current is destination that we want, we want to reconstruct the path and return it, and brake the loop if current == v1: current_path = v1 next_path = v1 count = 0 path.append(current_path) next_path = previous[path[count]] while current_path != next_path: path.append(next_path) current_path = next_path next_path = previous[path[count + 1]] count += 1 path.reverse() return path neighbors = self.getNeighbors(current) neighbors.sort() for x in neighbors: if previous[x] == -1: q.enqueue(x) previous[x] = current return None
def __init__(self, simulation_hours: float, arrival_average: float): #simulation hours + time it takes for all remaining trains to depart self.simulation_hours = simulation_hours self.arrival_average = arrival_average self.line = myQueue.Queue() self.train_times = self._gen_train_times() self.dock = None
def _gen_train_times(self): total_time = 0 t = self._gen_next_arrival() final = myQueue.Queue() count = 0 while total_time + t < self.simulation_hours: total_time = round(total_time + t, 2) final.put(total_time) t = self._gen_next_arrival() return final
def hotPotato(namelist, num): qu = myQueue.Queue() for name in namelist: qu.enqueue(name) while qu.size() > 1: for i in range(num): qu.enqueue(qu.dequeue()) qu.dequeue() return qu.dequeue()
import myQueue as mq j = mq.Queue() j.enqueue(3) j.enqueue(4) j.enqueue(5) j.dequeue() print(j.dequeue())