Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Richard T. Watson

6th Edition

1943153035, 978-1943153039

More Books

Students also viewed these Databases questions

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago