Question: You will write a simple program for arranging the records in a file by increasing order of the keys for each record. This program should
You will write a simple program for arranging the records in a file by increasing order of the keys for each
record. This program should be invoked as follows assuming that you are using Linux or mac and the
program is compiled into an executable. If you are using python this will be a bit different and it will still
be acceptable:
arrange i inputfile o outputfile
The above line means the users typed in the name of the program arrange and gave it two inputs: an
input file to work on called inputfile and an output file to put the results into called outputfile
I provide you with an input file called input and it has rows. The file is binary with each row having
bytes. The first four bytes are corresponding to a key and the last bytes are corresponding to the
value of the record. Thus, the input file contains a series of byte records, the first four bytes of which
are an unsigned bit integer key, and the remaining bytes of which are integers that form the rest of
the record.
Your goal: to build a program called arrange that takes in this file and arranges it based on the byte
key in increasing order using insertion sort. The remainder of the record should of course be kept with
the same key.
The output should be written to the specified output file. Note that the input file will be in binary, but the
corresponding output file should be in ascii. In order to read the input file and see its contents in ascii, I
provide you with a program called dumpc In order to compile dump.c you would do this is assuming
you are running on linux or mac:
gcc o dmp dump.c
Now you should have an executable called dmp in your current directory and you can use it to read the
binary input file as follows:
dmp i input
When you do this the contents of the binary file are displayed to you in a nice, formatted manner on the
terminal.
Programming languages and formatting
You are free to use either C C or Python and should implement the algorithms yourself and NOT use
any library which provides an implementation of the algorithm.
Submission Guidelines
Please mention the programming language and version and it SHOULD WORK ON the CS servers. Your
submission must have the following:
A short report documenting the algorithm you used. This is a very crucial step. Can you compute
the running time in BigOh notation for your algorithm.
A README file that describes how the code can be compiled and run. Also list any external
dependencies that need to be satisfied for compiling and running the code. If your code fails to compile
YOU GET A ZERO.
Your submission should have a single point of entry for running the code, like a main method in C or its
equivalent in any other language
"sort.h:
#ifndef sorth
#define sorth
DO NOT EDIT THIS FILE
#define NUMRECS
typedef struct rect
unsigned int key;
unsigned int recordNUMRECS;
rect;
#endif sorth
"dump.c:
#include
#include
#include
#include
#include
#include
#include
#include "sort.h
void
usagechar prog
fprintfstderr "usage: s i file
prog;
exit;
int
mainint argc, char argv
arguments
char inFile nosuchfile;
input params
int c;
opterr ;
while c getoptargc argv, i:
switch c
case i:
inFile strdupoptarg;
break;
default:
usageargv;
open and create output file
int fd openinFile ORDONLY;
if fd
perroropen;
exit;
rect r;
while
int rc;
rc readfd &r sizeofrect;
if rc indicates EOF
break;
if rc
perrorread;
exit;
printfkey: u rec:", rkey;
int j;
for j ; j NUMRECS; j
printfu rrecordj;
printf
;
void closefd;
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
