Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

// Shell Sort // I want to use three different types of loops here #include #include #include using namespace std; // Functions prototype int myRand();

// Shell Sort

// I want to use three different types of loops here

#include

#include

#include

using namespace std;

// Functions prototype

int myRand();

void sortArray(int shellSort[], int number);

void displayArray(int shellSort[]);

int main()

{

int myArray[30];

srand((unsigned)time(NULL));

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

{

myArray[i] = myRand();

}

sortArray(myArray, 20); // Calling function sortArray

displayArray(myArray); // Calling function displayArray

return 0;

}

int myRand()

{

return(1 + rand() % 50); // return random number from 1 to 50

}

void sortArray(int shellSort[], int number)

{

int temp;

for(int x = 0; x < number; x++)

{

for(int j = 0; j < number; j++)

{

if(shellSort[j] > shellSort[j + 1])

{

temp = shellSort[j];

shellSort[j] = shellSort[j + 1];

shellSort[j + 1] = temp;

}

}

}

}

void displayArray(int shellSort[])

{

for(int y = 0; y < 20; y++)

{

cout << shellSort[y];

cout << endl;

}

}

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_2

Step: 3

blur-text-image_3

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

More Books

Students also viewed these Databases questions

Question

Differentiate 3sin(9x+2x)

Answered: 1 week ago

Question

Compute the derivative f(x)=(x-a)(x-b)

Answered: 1 week ago