Question: C + + . I have a project with a header file, Sort.h , and a . cpp file, Driver.cpp . There's an error in
C I have a project with a header file, Sort.h and a cpp file, Driver.cpp There's an error in the Driver and Im not sure how to fix it Specifically int arri needs a constant value. I would appreciate any help in fixing this and I would greatly appreciate an explanation. Sort.h #include
#include
#include
#include
using namespace std;
void swapint& a int& bswap the content of a and b
int temp;
temp a;
a b;
b temp;
void insertionSortint array, int size
int key, j;
for int i ; i size; i
key arrayi;take value
j i;
while j && arrayj key
arrayj arrayj ;
j;
arrayj key; insert in right place
void selectionSortint array, int size
int i j imin;
for i ; i size ; i
imin i; get index of minimum data
for j i ; j size; j
if arrayj arrayimin
imin j;
placing in correct position
swaparrayi arrayimin;
void bubbleSortint array, int size
for int i ; i size; i
int swaps ; flag to detect any swap is there or not
for int j ; j size i ; j
if arrayj arrayj when the current item is bigger than next
swaparrayj arrayj ;
swaps ; set swap flag
if swaps
break; No swap in this pass, so array is sorted
Driver.cpp: #include "Sort.h
int main
time variables
clockt start, stop;
create different array sizes
for int i ; i ; i
printf
Array of size d
i;
int arri;
for int j ; j i; j
generate random numbers for array
arrj rand;
for insertionSort
start clock;
insertionSortarr i;
stop clock;
printf
Insertion sort: lfus", doublestop start CLOCKSPERSEC;
for int j ; j i; j
generate random numbers for array
arrj rand;
for bubbleSort
start clock;
bubbleSortarr i;
stop clock;
printf
Bubble sort: lfus", doublestop start CLOCKSPERSEC;
for int j ; j i; j
generate random numbers for array
arrj rand;
for selectionSort
start clock;
selectionSortarr i;
stop clock;
printf
Selection sort: lfdoublestop start CLOCKSPERSEC;
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
