'''Post: Returns the number of items in the PQ. In another docs page, heapq, it suggests the use of a counter. Suppose data 'item 2', is enqueued before 'item 1', item 1 will still go first. It appears the queue will be sorted by priority then data, which may not be always correct. '''Post: Removes and returns the highest priority item from the PQ.''' A typical pattern for entries is a tuple in the form: (prioritynumber, data). '''Post: Returns but does not remove the highest priority item from the PQ.''' '''Post: Item is inserted with specified priority in the PQ.''' ![]() So this is working but like I previously stated I am having trouble on how to make a priority queue out of this? I know asking for code is wrong, but I'm desperate could anyone help me out here? I have the basic rundown on what I want my priority code to do. Priority queues and the functions in the Python heapq module can often help with that. Programming is full of optimization problems in which the goal is to find the best element. # Since delete_max calls pop to remove an item, we need to append a dummy value to avoid an illegal index. A priority queue is a powerful tool that can solve problems as varied as writing an email scheduler, finding the shortest path on a map, or merging log files. Post: Heap property is satisfied for entire heap. ''' Pre: Self.heap has values in 1 to self.heap_size Post: Item is inserted in proper location in heap.''' Post: Maximum element in heap is removed and returned. Post: Heap Property is satisfied for the entire heap.''' '''Pre: Items from 0 to position - 1 satisfy the Heap property. '''Post: Returns the number of items in the heap.''' '''Post: A heap is created with specified items.''' Please I have been stuck on this for awhile and really need some help. ![]() Could anyone help me on how to make a working Priority Queue class? I have the basic function names written down but I have no idea on where to go from there. I tried looking up help on the internet but I keep getting answers with people using either the "queue" or "heapq" python implementation. However, I need help on the Priority Queue part of my code. I have made a heap class and I am trying to make a PriorityQueue class as well so both of them can work together.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |