I have to write a program in c that implements binary heaps. I am not too sure w
ID: 3693039 • Letter: I
Question
I have to write a program in c that implements binary heaps. I am not too sure where to start.
Objective By completing this assignment, students will demonstrate a working knowledge of the following Binary Heap concepts: 1. Code implementation of BH 2. Traversing BH 3. Algorithm for inserting nodes into a BH 4. Deleting nodes from a BH 5. Searching for values in BH
Problem: Managing the Printer Queue You are working as an intern at the GreenPrinters Company. Your job is to write the software to program the ‘printing job spooling functionality’ of the latest printer model. Your code should be able to: 1. Read jobs one at a time from a file and add them to a binary heap ordered on the priority of the job (the lower the priority number, the higher the priority)- Example 8 has higher priority than 15. 2. Service the jobs in the queue each in its turn while maintaining the integrity of the BH a. Servicing a job means that this job is deleted from the queue
Each Job is comprised of the following information: The name of the file to be printed (no more than 35 characters) The priority of the job (a positive integer)
When run, your program should read a batch file of jobs. Each line of the file contains information about 1 job as described in the input file structure section.
If a job is waiting in the batch file (meaning that its arrival time is before or equal to the current time), your printer will en-queue that job before printing the next job. Otherwise your printer will print the next job. The time stamp is implemented as a simple integer. When the program begins that is time 0, the next operation will be at time 1 etc.
A success message will be output to the output file each time a job has been successfully enqueued. A list of the waiting jobs will also be printed as shown in the sample output. When a job is printed, a message is output indicating the name of the file that has been printed and the time. This is followed by a list of the names of the files still waiting in the printing queue. If no job is waiting in the queue and there is no job in the batch file at that time, your printer will print a Ready message. For the sake of simplicity you may assume that at any time, the printer can either print a job or en-queue a job–but not both.
2
Structure of the inputfile (jobs.txt) The input file contains a set of jobs each on a separate line. A line begins with an integer indicating the arrival time of the job, followed by a string indicating the file name. The line ends with a positive integer indicating the priority of the job.
Output Specification
Your output should match that in the sample output. You are to use the exact text. Do not change the response text.
Implementation Restrictions a. The file names have no spaces b. Your output file should be called output.txt c. Your program should expect an input file called jobs.txt d. If 2 jobs of the same priority are on the queue, the first job to arrive is processed first
Sample Input File
0 Exam2.pdf 4
1 FacialRecognitionSystems.pdf 2
4 ComputerGraphics.cgl 5
6 DenotationalSemantics.c 1
7 Input.in 3
8 ClassList.txt 2
3
Sample Output File (output.txt)
Time 0
---------
Exam2.pdf has been added to the queue
Exam 2 is waiting to be printed
Time 1
--------
Facial Recognition Systems.pdf has been added to the queue
Facial Recognition Systems.pdf Exam 2.pdf Are waiting to be printed
Time 2
---------
Facial Recognition Systems.pdf has been printed
Exam 2.pdf is waiting to be printed
Time 3
---------
Exam 2.pdf has been printed
Printer is ready
Time 4
--------
ComputerGraphics.cgl has been added to the queue
ComputerGraphics.cgl is waiting to be printed
Time 5
---------
ComputerGraphics.cgl has been printed
Printer is ready
4
Time 6
--------
DenotationalSemantics.c has been added to the queue
DenotationalSemantics.c is waiting to be printed
Time 7
--------
Input.in has been added to the queue
DenotationalSemantics.c Input.in are waiting to be printed
Time 8
---------
ClassList.txt has been added to the queue
DenotationalSemantics.c
ClassList.txt
Input.in
are waiting to be printed
Time 9
--------
DenotationalSemantics.c has been printed
ClassList.txt
Input.in
are waiting to be printed
Time 10
--------
ClassList.txt has been printed
Input.in
is waiting to be printed
5
Time 11
--------
Input.in has been printed
Printer is ready