Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The objectives of this assignment are to write a program to implement a simple priority queue using a sorted, singularly linear linked list data structure.
The objectives of this assignment are to write a program to implement a simple priority queue using a sorted, singularly linear linked list data structure. The priority queue code should be structured as if it were part of a software library to be used with other prog someone else. Small keys indicate higher priority. The software should implement the following interface rams written by 1. Use a typedef to define a data structure called Prioo, defined as a C struct representing the priority queue. The implementation of the data structure is not visible outside the library you are creating 2. Write a function with the prototype Priog *PO_create()i Create a new priority queue and return a pointer to it. The priority queue is initially empty, i.c., contains no elements. Return NULL if the operation failed, c.g., due to a lack of memory 3. Write a function with the prototype int PQ_insert(Prioo *PQ, double key, void "data); Insert the item pointed to by data into the priority queue PQ. The priority of this data item is key. Return NULL if the operation failed, or an arbitrary value not equal to NULL if it succeeded. The data type of the inserted item pointed to by data is defined by the caller, and is not visible to the priority queue library 4. Write a function with the prototype void *PQ_delete (Priog *PQ, double *key); Remove the data item from the priority queue PQ with the smallest key (priority). The function returns a pointer to the data item that was removed, or NULL if the queue was empty. The priority of the deleted item is returned in key 5. Write a function with the prototype Unsigned int PQ count (PrioQ *PQ) Returns the number of items crrently residing in the priority queue 6. Write a function with the prototype void *PQ free (struct PrioQ *PQ) Delete the priority queue Po by releasing all memory used by the contents of the data structure 7. Write a program to test your priority queue library. The test program should first create a priority queue, create 20 data elements, assign each a priority drawn from a random number generator and insert it into the queue. Then remove the elements one after another and verify that the priority of the removed items is in increasing order. Include print statements to demonstrate correct operation
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started