Priority Queue: =============== list ==> [1,2,3,4,5] iteration: order/sequence priority Queue => [1,3,5,7,9] each element ==> priority 7 ==> high 9 ==> second 3 ==> third 1 ==> fourth 5 ==> last # Priority Queue class priorityQueue: def __init__(self): self.queue = [] # empty priority Queue def __str__(self): return ' '.join([str(i) for i in self.queue]) def isEmpty(self): return len(self.queue) == [] def insert(self,item): self.queue.append(item) def delete(self): try: highest_priority = 0 for i in range(len(self.queue)): if self.queue[i] > self.queue[highest_priority]: highest_priority = i item = self.queue[highest_priority] del self.queue[highest_priority] return item except IndexError: print("This Queue is Empty.") return None pq = priorityQueue() pq.insert(400) pq.insert(300) pq.insert(500) pq.insert(700) pq.insert(900) print(pq.queue) print(pq.isEmpty()) val1 = pq.delete() print(val1) print(pq.delete()) print(pq.delete()) print(pq.delete()) print(pq.delete()) print(pq.delete()) ======================================= Heap Queue: =========== # heap import heapq from heapq import heapify, heappush # defining the heap heap_data = [1000,123,5797,7997,97,1001,1023,1225] # list # Transform the list into heapqueue heapq.heapify(heap_data) # 7997 5797 2001 1993 1225 1073 1023 1001 1000 123 97 print(heap_data) # Adding elements into heapqueue heapq.heappush(heap_data,1073) heapq.heappush(heap_data,1993) heapq.heappush(heap_data,2001) print(heap_data) pop_element = heapq.heappop(heap_data) print(pop_element) ===========================================================