Answered step by step
Verified Expert Solution
Question
1 Approved Answer
input_short.txt - Windows CI9:# g(F) By(E) MN(0) 47IM) 582(H) NSERT 1 INSERT 2 INSERT 3 INSERT 4 INSERT 5 ASCEND DESCENDThe first argument is the
input_short.txt - Windows CI9:# "g(F) By(E) MN(0) 47IM) 582(H) NSERT 1 INSERT 2 INSERT 3 INSERT 4 INSERT 5 ASCEND DESCENDThe first argument is the name of the input file. (3) If the number of command-line arguments is not 1 (zero or more than 1), then you should print a usage string on the display and exit the program. The usage string looks like this: usage: ./hw2 input_filename (4) If the input file does not exist, your program should display an error message on the screen and terminate. The error message should be: The input file does not exist. (5) The input file format is like the following. Each line contains one command. INSERT 5 INSERT 8 INSERT 3 ASCEND INSERT 10 DESCEND Example input files will be given for your reference. At the evaluation, the TA will use a different input file. You may assume that the format of the input file is always correct; You do not need error handling for the contents of the input file. (6) At the end of the program, you should print the following lines on the screen. output written to hw2_result . txt. running time: 0. 052411 seconds The actual running time printed will be different on each run. In order to print out the running time, use the function clock( ). (7) Similar to other homework, you should write a Makefile. The TA will build your code by running "make". It should create a binary file, "hw2".In this project, we will implement a sorting program using a heap. Specically, we will write a program that reads a list of commands from an input le and execute them, while maintaining a min heap and a max heap. Duplicate data can be inserted into the heap. There are three commands that need to be supported by the program: ( I) insert - This command inserts an integer into both the min heap and the max heap. If the line reads "INSERT 3", the program should insert a new element with data = 3 to the min heap and the max heap. (2) print data in the ascending order - The command "ASCEND" prints the elements in the heap in the ascending order. At this command, the program should write a line which contains the sorted elements in the output le named "hw2_result.txt". (Try running the given binary le.) - You will need to use the min heap to execute this command. Alter printing data in the ascending order, you should still have the min heap with all the elements in it. Since you will need to delete elements from the min heap in order to accomplish this task, you should make a copy of the min heap before you start deleting the elements. (3} print data in the descending order - The command "DESCEND" prints the elements in the heap in the descending order. At this command, the program should write a line which contains the sorted elements in the output le named "hw2_result.txt". (Try running the given binary le.) - You will need to use the max heap to execute this command. After printing data in the descending order, you should still have the max heap with all the elements in it. Since you will need to delete elements from the min heap in order to accomplish this task, you should make a copy of the max heap before you start deleting the elements
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