def __init__(self, G): self.__marked = [False] * G.V() self.__pre = [-1] * G.V() self.__post = [-1] * G.V() self.__pre_counter = 0 self.__post_counter = 0 self.__pre_order = Queue() self.__post_order = Queue() for v in range(G.V()): if self.__marked[v] is False: self.__dfs(G, v)
def test_iter2(): q = Queue() r = Queue() list = [i for i in range(10)] for i in list: r.queue(i) assert not r.is_empty() for i in r: q.queue(i) assert r.is_empty() assert not q.is_empty() new_list = [i for i in q] assert q.is_empty() assert list == new_list
def test_iter(): q = Queue() list = [i for i in range(10)] for i in list: q.queue(i) new_list = [i for i in q] assert q.is_empty() assert list == new_list
def hotPotato(namelist, num): simqueue = Queue() for name in namelist: simqueue.enqueue(name) while simqueue.size() > 1: for i in range(num): simqueue.enqueue(simqueue.dequeue()) simqueue.dequeue() return simqueue.dequeue()
def test_queue_more(): q = Queue() q.queue(1) q.queue('true') q.queue(True) assert q.dequeue() == 1 assert q.dequeue() == 'true' assert q.dequeue() == True assert q.is_empty()
def __bfs(self, G, sources): q = Queue() for s in sources: self.__marked[s] = True self.__dist_to[s] = 0 q.enqueue(s) while q.is_empty() is False: v = q.dequeue() for w in G.adj(v): if self.__marked[w] is False: self.__edge_to[w] = v self.__dist_to[w] = self.__dist_to[v] + 1 self.__marked[w] = True q.enqueue(w)
def enqueue(self, item, priority=0): if priority not in self.items: self.items[priority] = Queue() queue = self.items[priority] queue.enqueue(item)
import redis from pyqueue import Queue r = redis.StrictRedis() queue = Queue(r, 'pynash') print('Starting worker...') while True: print(' --> Waiting for work...') job = queue.dequeue_job() print('Job {job_id}: {result}'.format(job_id=job.id, result=job.result))
from pyqueue import Queue q=Queue() q.enqueue(6) q.enqueue('cat') q.enqueue(True) print(q.size()) print(q.dequeue()) print(q.dequeue()) print(q.size())
def test_queue_one(): q = Queue() q.queue(1) assert not q.is_empty() assert q.dequeue() == 1 assert q.is_empty()
def test_empty(): q = Queue() assert q.is_empty()
def test_queue_none(): q = Queue() q.queue(None) assert not q.is_empty() assert q.dequeue() is None assert q.is_empty()