Is there a library for C that provides priority queues? I'm interested in open source libraries that are commonly installed on Linux machines, something of the kind of glib, which provides some data structures.
Also, you will learn about it's implementations in Python, Java, C, and C++. A priority queue is a special type of queue in which each element is associated with a priority value. And, elements are served on the basis of their priority. That is, higher priority elements are served first.
C is not an object-oriented language, and it doesn't have standard libraries for things like queues. For C++, look for the std::queue. You can, of course, make queue-like structure in C, but you'll wind up doing a lot of the work yourself.
The binary heap is the most efficient method for implementing the priority queue in the data structure.
Priority Queues can be implemented using common data structures like arrays, linked-lists, heaps and binary trees. The list is so created so that the highest priority element is always at the head of the list. The list is arranged in descending order of elements based on their priority.
Some random link:
In general, books dealing with Linux Kernel and Linux System Programming contain valuable materials related to queues and their implemention details.
You may be able to just use message queues, depending on how big the queues need to be.
With posix message queues (see man mq_overview
) you can set message priorities.
Alternately, with System V message queues (msgget()
, msgsnd()
, msgrcv()
), you can use the message type as a priority and try retrieving each priority (type) in sequence from highest priority to lowest.
In either case they're standard IPC, and should be available on any normal Linux distribution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With