Question: Write a C ++ program to fill a vector with 5000 random numbers. Then display: The smallest number The largest number The number of odd
Write a C ++ program to fill a vector with 5000 random numbers. Then display:
The smallest number
The largest number
The number of odd values
The number of even values The total of the values
The average of the values
Ask the user for an integer and display the subscript of the cell where it was found or NOT FOUND! if it isnt found.
Since you will be using a binary search, the vector will have to be in order. Each of the preceding values should be determined by a function and returned to main where they should be displayed.
Here is the code for shellSort and swapper function .
void shellSort(vector
{
bool flag = true;
int i, numLength = V.size();
int d = numLength;
while (flag || (d>1)) // bool flag
{
flag = false; //reset flag to 0 to check for
// future swaps
d = (d + 1) / 2;
for (i = 0; i < (numLength - d); i++)
{
if (V[i + d] < V[i])
{
swapper(V[i], V[i + d]);
flag = true; //tells swap has occurred
}
}
}
}
void swapper(int &a, int &b)
{
int temp;
temp = a;
a = b;
b = temp;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
