Question: Question: Please add a Shuffle Array to the C++ program below. Please display how many shuffles. #include #include #include #define SIZE 100 #define LIMIT 50

Question:

Please add a Shuffle Array to the C++ program below. Please display how many shuffles.

#include

#include

#include

#define SIZE 100

#define LIMIT 50

using namespace std;

void display(int *a, int n)

{

int i;

cout << " \tFirst Element:" << a[0] <<" \t";

cout<<" \tDisplaying the array: \t";

for (i = 0; i < n; i++)

{

cout<

}

}

int partition(int *a,int p,int r)

{

int q = p-1, i;

//First Element

int temp = a[0];

for (i = p; i < r; i++)

{

if (a[i] >= a[r]) //descending or acsending (change greater/less than sign)

{

++q;

temp = a[q];

a[q] = a[i];

a[i] = temp;

}

}

++q;

temp = a[q];

a[q] = a[r];

a[r] = temp;

return q;

}

void quickSort(int *a, int p, int r)

{

if (p < r)

{

int q = partition(a,p,r);

quickSort(a, p, q - 1);

quickSort(a, q + 1, r);

}

}

int main(int argc, char* argv[])

{

{

cout<<"Quick sort : \t";

srand(time(NULL));

int a[SIZE];

for (int i = 0; i < SIZE; ++i)

{

a[i] = rand() % LIMIT +1;

}

display(a, sizeof(a)/sizeof(int));

quickSort(a, 0, sizeof(a)/sizeof(int) - 1);

display(a, sizeof(a)/sizeof(int));

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!