Question: #include #include void ascend ( int A [ ] , int N ) { for ( int i = 0 ; i < N; i
#include
#include
void ascendint A int N
for int i ; i N; i
Ai i ;
void descendint A int N
for int i ; i N; i
Ai N i;
void veeint A int N
int mid N ;
for int i ; i mid; i
Ai N i;
for int i mid; i N; i
Aii mid;
void zigzagint A int N
int left right N ;
for int i ; i N; i
if i
Ai N left;
else
Ai right N left;
void randomfillint A int N
for int i ; i N; i
Ai randN ;
long insertSortint A int N
long comparisons ;
for int i ; i N; i
int key Ai;
int j i ;
while j && Aj key
Aj Aj; j;
comparisons;
Aj key; comparisons;
return comparisons;
long quickSortint A int N
long comparisons ;
Helper function
void quickSortHelperint A int low, int high
if low high
int pivot Ahigh;
int i low ;
for int j low; j high; j
comparisons;
if Aj pivot
i;
int temp Ai; Ai Aj;
Aj temp;
int temp Ai ;
Ai Ahigh;
Ahigh temp;
quickSortHelperA low, i;
quickSortHelperA i high;
quickSortHelperA N ;
return comparisons;
long mergeSortint A int N
long comparisons ;
void mergeint A int left, int mid, int right
int n mid left ; int n right mid;
int Ln Rn;
for int i ; i n; i Li Aleft i;
for int j ; j n; j Rj Amid j;
int i j k left;
while i n && j n
comparisons;
if Li Rj
Ak Li;
else
Ak Rj;
while i n Ak Li;
while j n Ak Rj;
void mergeSortHelperint A int left, int right
if left right
int mid left right left;
mergeSortHelperA left, mid;
mergeSortHelperA mid right;
mergeA left, mid, right;
mergeSortHelperA N ;
return comparisons;
void runSortingchar filename
FILE file fopenfilenamer;
if file
printfFailed to open file.
;
return;
int R;
fscanffiled &R;
for int i ; i R; i
int N;
char inputType, sortType;
fscanffiled c c &N &inputType, &sortType;
int AN;
switch inputType
case A: ascendA N;
break;
case D: descendA N; break;
case V: veeA N;
break;
case Z: zigzagA N;
break;
case R: randomfillA N; break;
long comparisons ;
switch sortType
case I: comparisons insertSortA N;
break;
case Q: comparisons quickSortA N;
break;
case M: comparisons mergeSortA N;
break;
printfd c c ld
N inputType, sortType, comparisons;
fclosefile;
int mainint argc, char argv
if argc
printfUsage: s
argv;
return ;
runSortingargv;
return ;
WHAT WOULD THE CONTROL FILE LOOK LIKE?
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
