def merge_queue(queue1, queue2): #write your logic here a = queue1.get_max_size() b = queue2.get_max_size() merged_queue = Queue(a + b) lst1 = [] lst2 = [] while not queue1.is_empty(): lst1.append(queue1.dequeue()) while not queue2.is_empty(): lst2.append(queue2.dequeue()) merged = [] if (a < b): for i in range(0, a): merged.append(lst1[i]) merged.append(lst2[i]) for i in range(a, b): merged.append(lst2[i]) else: for i in range(0, b): merged.append(lst1[i]) merged.append(lst2[i]) for i in range(b, a): merged.append(lst1[i]) for i in merged: merged_queue.enqueue(i) return merged_queue
def check_numbers(number_queue): #write your logic here solution_queue1 = Queue(number_queue.get_max_size()) while not (number_queue.is_empty()): pop = number_queue.dequeue() count = 0 for x in range(1, 11): if pop % x == 0: count += 1 if count == 10: solution_queue1.enqueue(pop) return solution_queue1
def separate_boxes(box_stack): #Remove pass and write your logic here new_queue = Queue(box_stack.get_max_size()) lst2 = [] lst = ['Red', 'Green', 'Blue'] while not box_stack.is_empty(): ele = box_stack.pop() if (ele not in lst): new_queue.enqueue(ele) else: lst2.append(ele) for i in lst2[::-1]: box_stack.push(i) return new_queue
def check_numbers(number_queue): #write your logic here solution_queue1 = Queue(number_queue.get_max_size()) while not number_queue.is_empty(): ele = number_queue.dequeue() count = 0 i = 1 while i <= 10: if (ele % i == 0): count += 1 i += 1 if (count == 10): solution_queue1.enqueue(ele) return solution_queue1
def separate_boxes(box_stack): que = Queue(box_stack.get_max_size()) lst = [] while not (box_stack.is_empty()): poped = box_stack.pop() if poped in ["Red", "Blue", "Green"]: lst.append(poped) else: que.enqueue(poped) while len(lst) != 0: box_stack.push(lst.pop()) return que #Remove pass and write your logic here pass
class Company: def __init__(self, emp_list): self.__employees = emp_list self.__pending_jobs = Queue(10) def get_employees(self): return self.__employees def get_pending_jobs(self): return self.__pending_jobs def allocate_new_job(self, job): in_job = 0 for employee in self.__employees: if employee.get_allocated_job() is None: employee.set_allocated_job(job) break else: in_job += 1 if in_job == len(self.__employees): self.__pending_jobs.enqueue(job) pass def elapsed_time(self, no_of_mins): completed_list = [] for employe in self.__employees: job_status = employe.elapsed_time(no_of_mins) if employe.get_allocated_job() is None: self.allocate_new_job(self.get_pending_jobs().dequeue()) if job_status is not None: completed_list.append(job_status) if len(completed_list) != 0: return completed_list else: return None
class Company: def __init__(self, emp_list): self.__employees = emp_list self.__pending_jobs = Queue(100) def get_employees(self): return self.__employees def get_pending_jobs(self): return self.__pending_jobs def allocate_new_job(self, job): flag = 0 for i in self.__employees: if (i.get_allocated_job() is None): i.set_allocated_job(job) flag += 1 break else: continue if (flag == 0): self.__pending_jobs.enqueue(job) def elapsed_time(self, no_of_mins): complete_list = [] for i in self.__employees: status = i.elapsed_time(no_of_mins) if i.get_allocated_job() is None: self.allocate_new_job(self.__pending_jobs.dequeue()) if (status): complete_list.append(status) if (len(complete_list) > 0): return complete_list else: return None
def merge_queue(queue1, queue2): #write your logic here if queue1.get_max_size() > queue2.get_max_size(): big = queue1 small = queue2 else: big = queue2 small = queue1 merged_queue = Queue(queue1.get_max_size() + queue2.get_max_size()) count = 1 for y in range(small.get_max_size() * 2): if count % 2 == 0: merged_queue.enqueue(queue2.dequeue()) else: merged_queue.enqueue(queue1.dequeue()) count += 1 for x in range(big.get_max_size() - small.get_max_size()): merged_queue.enqueue(big.dequeue()) return merged_queue
#DSA-Assgn-14 #This assignment needs DataStructures.py file in your package, you can get it from resources page from res.DataStructures import Queue def check_numbers(number_queue): #write your logic here solution_queue1 = Queue(number_queue.get_max_size()) while not (number_queue.is_empty()): pop = number_queue.dequeue() count = 0 for x in range(1, 11): if pop % x == 0: count += 1 if count == 10: solution_queue1.enqueue(pop) return solution_queue1 #Add different values to the queue and test your program number_queue = Queue(5) number_queue.enqueue(13983) number_queue.enqueue(10080) number_queue.enqueue(7113) number_queue.enqueue(2520) number_queue.enqueue(2500) check_numbers(number_queue)
def __init__(self, emp_list): self.__employees = emp_list self.__pending_jobs = Queue(100)
count = 1 for y in range(small.get_max_size() * 2): if count % 2 == 0: merged_queue.enqueue(queue2.dequeue()) else: merged_queue.enqueue(queue1.dequeue()) count += 1 for x in range(big.get_max_size() - small.get_max_size()): merged_queue.enqueue(big.dequeue()) return merged_queue #Enqueue different values to both the queues and test your program queue1 = Queue(3) queue2 = Queue(6) queue1.enqueue(3) queue1.enqueue(6) queue1.enqueue(8) queue2.enqueue('b') queue2.enqueue('y') queue2.enqueue('u') queue2.enqueue('t') queue2.enqueue('r') queue2.enqueue('o') merged_queue = merge_queue(queue1, queue2) print("The elements in the merged queue are:") merged_queue.display()