Priority Queue List

I have a college programming project in C ++ divided into two parts. I begin the second part where it is supposed to use priority_queues , hash tables and BST .

I am having problems (at least) with priority queues, since it obliges me to redo a lot of code already implemented in the first part.

The project is about introducing a simple airport management system and, therefore, I have classes such as airport (main class), plane, terminal and flight. My airport had list terminals, but now the project specification indicates that I should support the terminals in priority_queue , where the top of the terminal is less busy, i.e. has fewer flights.

For each class I have CRUD functions, but now, as I suppose, for example, edit the terminal and add a flight to it? With the list, I just had to move to a certain position, but now I only have access to the object at the top of the queue. The solution I was thinking about was copying the priority queue terminals to a temporary list, but to be honest, I don't like this approach.

What should I do?

Thanks in advance.

+3
c ++ iterator list priority-queue
source share
1 answer

It looks like you need a priority queue with effective increases and decreases in key operations. You might be better off creating your own queue queue implementation.

The priority_queue container is great for dynamic collections. But since the number of terminals at the airport is pretty much fixed, you can use a container with a fixed size with a bunch of algorithms.

You can use any container that provides random access iterators (vector, array, deque) as an internal storage. Then use the functions make_heap (), sort_heap () to heapify the array. Now you can cheaply access the vertex (), change the priority of a random item on the heap, and easily iterate over all the items.

For an example see http://www.cplusplus.com/reference/algorithm/make_heap/

+2
source share

All Articles